Q&A > database programming
Description:
I am trying to use MySQL through Perl (but this has also happened doing other things). I can print before I connect, but afterwards it won't print. I cann't be sure if it is connecting or not because I can't get any print out to see. Below, I get print 1 and 2, but not 3. Is this Perl or some server problem?#!/usr/bin/perl print "Content-type: text/html\n\n"; print "OK 1"; use DBI; print "OK 2"; $dbh = DBI->connect("DBI:mysql... $dbh->disconnect(); print "OK 3";
Answer: How can I see error messages from MySQL? contributed by autark The fact that it doesn't print "OK 3" suggests that something went wrong inbetween "OK 2" and "OK 3". You don't see the error message, because it's printed to STDERR, and the HTTP-server doesn't catch that output. Try to put this in your script: use CGI::Carp qw(fatalsToBrowser); This will ensure that messages to STDERR will be displayed in your browser so that you easier can diagnose the problem. Autark |
Answer: How can I see error messages from MySQL? contributed by BBQ DBI has return values for each one of its calls, so it would be wise to or your connect statement, like: this way, you'll always get an error message if something goes wrong. |
Answer: How can I see error messages from MySQL? contributed by btrott To follow up with what BBQ wrote... you can either check the return value of your database functions, or you can just use the RaiseError attribute, which will die on an error:
|
Answer: How can I see error messages from MySQL? contributed by PsychoSpunk To continue the follow up to the previous follow up... if you RaiseError, you may find it handy to use the variable for the error string produced by the DBMS irregardless of which one you choose. This of course is $DBI::errstr which will return the ever cryptic messages that seem to be returned from every DBMS I've used. |
Answer: How can I see error messages from MySQL? contributed by pmas DBI has excellent function DBI->trace(2), printing a string for each DBI action made (as connect, prepare, execute). Will even show you which data were fetched, row by row. Excellent for debug. |
Please (register and) log in if you wish to add an answer
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |