1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Rep Power

    Printing mySQL Error Msgs in Browser

    Can't figure out how to get mySQL error messages to display in the browser when I execute the script. I use:

    use CGI qw(:standard);
    use CGI::Carp qw(fatalsToBrowser);
    use DBI;

    print "Content-type: text/html\n\n";

    $dbh = DBI->connect ("DBI:mysql:host=localhost;database=dbname","user","pw",{PrintError => 1, RaiseError => 1});

    (I then build by SQL statement and then

    $sth = $dbh->prepare ("$sql_stmt");

    The program bombs at $sth->execute() with an OK message followed by "The server encountered an internal error or misconfiguration and was unable to complete your request." No SQL error message.

    The only way I can see the SQL error message is if I hardcode some dummy values and run the script from the shell. I know I must be missing some code here to get the mySQL error messages to appear in the browser. Any ideas?

  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    The Emerald City
    Rep Power

    Re: Printing mySQL Error Msgs in Browser

    Change the execute statment to
    $sth->execute() or die $sth->errstr;
    That should generate an error message about why the execute statement is bombing.


IMN logo majestic logo threadwatch logo seochat tools logo