Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

DBD::mysql does not return errorstring

by Skeeve (Vicar)
on May 12, 2014 at 09:34 UTC ( #1085765=perlquestion: print w/ replies, xml ) Need Help??
Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

I have this code, which fails to report an error when I deliberately use a non existing database tabel:

use DBI; # Load the DBI module ### Perform the connection using the Oracle driver my $dbh = DBI->connect( "dbi:mysql:MYDB:localhost:3306", "NYUSER", "MY +PASS", { PrintError => 0, RaiseError => 0 } ) or die "Can't connect to the database: $DBI::errstr\n"; ### Prepare a SQL statement for execution my $sth = $dbh->prepare( "UPDATE user_settingsX set `language`=? WHERE + `username` = ?" ) or die "Can't prepare SQL statement: $DBI::errstr\n"; ### Execute the statement in the database $sth->execute("fr", "admin") or die "Can't execute SQL statement: ",$sth->errstr,"\n"; ## I also tried: "Can't execute SQL statement: $DBI::errstr\n"; ### Disconnect from the database $dbh->disconnect or warn "Error disconnecting: $DBI::errstr\n"; exit;

I would expect the an error message telling me that the tabel "user_settingsX" does not exist, but the errstr is undef.

I'm using:

  • Windows 7
  • strawberryperl 5, version 18, subversion 1 (v5.18.1) built for MSWin32-x64-multi-thread
  • DBD::mysql 4.023
  • DBI 1.628


Comment on DBD::mysql does not return errorstring
Select or Download Code
Replies are listed 'Best First'.
Re: DBD::mysql does not return errorstring
by Skeeve (Vicar) on May 12, 2014 at 10:21 UTC

    Again I reply to myself ;)

    So for reference purposes: Update to a newer Version of strawberry perl (and so to a newer DBD::mysql) resolved the issue.

    I'm now using

    • Windows 7
    • strawberryperl 5, version 18, subversion 2 (v5.18.2) built for MSWin32-x64-multi-thread
    • DBD::mysql 4.027
    • DBI 1.631

Re: DBD::mysql does not return errorstring
by leslie (Pilgrim) on May 12, 2014 at 11:10 UTC


    You should enable any one of the automatic error checking. Below I have enable warning

    PrintError => 1, # To enable warnings RaiseError => 0 # To enable die

    If both RaiseError and PrintError are enabled, an error will cause warn( ) and die( ) to be executed sequentially.

      That does not help as:

      1. I did not want to print diagnostics in my production code but handle the error in my code. Note: The posted code is a small example code. It is not my actual production code.
      2. But even with diagnostics on, there was no error reported.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1085765]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2015-11-27 05:03 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (718 votes), past polls