I'm trying to open a database in my main program, pass 3 arguments to this
module (list of field names, table name and additional SQL arguments) then
retrieve and forward the data to a waiting variable in the main program.
Every time I run it from a command line I get the following message:
Can't call method "prepare" on an undefined value at
/usr/lib/perl5/5.6.0/DBGet.pm line 19.
(Running from a browser only returns a blank screen). The only way I can
get it to work from this module is to uncomment the "our $dbh ..."
statement. As a subroutine in the main program it works fine. I need to
have this as a module so I can call it from several webpages, each one a
separate Perl script.
My question is: how can I open the database once in the main program and
have it visible to this module? I don't want to have to reestablish
connections repeatedly for each query for dozens of concurrent users.
In the main program I do this:
...
use DBGet;
...
our $dbh = DBI->connect("dbi:mysql:dbname:","user","password");
...
my ($lookup_colist) = build_lookup_table("clli", "common_co_list", "order by
clli");
...
Thanks in advance for your help.
Joe Mecklin
########## Program listing ###########
package DBGet;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(build_lookup_table);
our $VERSION = 0.01;
sub build_lookup_table
{
# $_[0] = list of fields to retrieve
# $_[1] = table name to retrieve fields from
# $_[2] = any additional arguments
#our $dbh = DBI->connect("dbi:mysql:dbname:","user","password");
my $statement = "select $_[0] from $_[1]";
$statement .= " $_[2]" if $_[2];
$sth = $dbh->prepare( "$statement" ); <------ line
19 from error message
$sth->execute();
return $sth->fetchall_arrayref();
}
1;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]