in reply to DBD DBI Mysql Connect

Hello Umdurman,

Similar question has been asked before Can't call method "prepare" on an undefined value.

Most likely you are not connecting to your database. Enter a validation error on your connection, sample of untested code bellow:

Change this:

$Dbh = DBI->connect($DbConnectionInfo,$DbUserid,$DbPasswd);

To this:

my $dbh = DBI->connect($DbConnectionInfo,$DbUserid,$DbPasswd, { RaiseE +rror => 1 });

From DBI documentation:

$dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 });

Update: I would also suggest to use error handling on your prepare statements also, if the connect to DB is good then the error is coming from the prepare statement.

Sample of untested code:

$Sth = $Dbh->prepare("SELECT RegNum FROM $DbUsers ORDER BY RegNum DESC + LIMIT 1") or die "Can't prepare: ", $dbh->errstr;

Update 2: Very useful tutorial / tips and tricks with DBI Tricks with DBI.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: DBD DBI Mysql Connect
by Umdurman (Acolyte) on Sep 10, 2017 at 21:47 UTC
    Thank you all guys, I found the solution. I run 2 domains on the testserver a .com and a .nl domain. The script was refering to the .com instead of the .nl My bad. Warm regards all, Ton
Re^2: DBD DBI Mysql Connect
by 1nickt (Canon) on Sep 11, 2017 at 14:08 UTC

    I would also suggest to use error handling on your prepare statements also ...

    It's not necessary to use "or die" with statement handle calls (or any calls) if you've set RaiseError to true in the DBI connection string.


    The way forward always starts with a minimal test.