You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by MEINL Thorsten FGTE <Th...@framatome-anp.com> on 2002/08/07 16:28:54 UTC

Problems mod_perl and DBI (DBD::mysql)

Hello,

The following small script
----------------------------------------------------------------------------
----
#!/usr/local/bin/perl
#
#

use strict;
use DBI;


my $dbh = DBI->connect("DBI:mysql:database=Dokuzentrum;host=localhost",
"http", "", { RaiseError  => 1 }) || die ("Cannot connect: $DBI::errstr");
 

my $sql = "SELECT * FROM benutzer WHERE (id = 1)";
my $allRef = $dbh->selectall_arrayref($sql);
----------------------------------------------------------------------------
--

gives the error message

Can't call method "prepare" on an undefined value at test.pl line 12

when run in mod_perl. I think, if I get this far, then what can be
undefined? Also $dbh IS defined,
print STDERR $dbh; gives Apache::DBI::db=HASH(0x8ecddf0).
Very strange I think...
The real problem occured in some modules in which I use $dbh with our($dbh)
(as I want to use the same connection in some other packages), and there I
run into a similar error, which looks like

Can't call method "DBD::mysql::db::SUPER::selectall_arrayref" on unblessed
reference at Session.pm line 86.

Again, if I get this far (he can resolve the $dbh object-reference), what
the hell is undefined or unblessed (sometimes the same error says "undefined
value")??
Forcing to reload all modules does not help either.
We are using mod_perl 1.27 with DBI 1.30.
Any suggestions?

Greetings

Thorsten

RE: Problems mod_perl and DBI (DBD::mysql)

Posted by Lucas Saud <lu...@uol.com.br>.
hi,

try this:

#!/usr/local/bin/perl -w

use strict;
use DBI;
my $dbh = DBI->connect("DBI:mysql:database=Dokuzentrum;host=localhost",
"http", "", { RaiseError  => 1 }) || die ("Cannot connect: $DBI::errstr");

my $sql = "SELECT * FROM benutzer WHERE (id = 1)";
my $sth = $dbh->prepare($sql) or die ("Cannot prepare: $sql with $DBI::errstr");
$sth->execute() or die ("Cannot execute: $DBI::errstr");

my $allRef = $sth->fetchall_arrayref({});

cheers, lucas