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:


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: DBD::mysql does not return errorstring
by Skeeve (Parson) 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

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: DBD::mysql does not return errorstring
by leslie (Pilgrim) on May 12, 2014 at 11:10 UTC

    Hi,

    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.

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e