Don't know if this appropriate or not, but I have recently been working a lot with cgi and mysql and after a certain amount of debugging hassle all sql statements were moved to a subroutine enabling us to see
1) what we actually tried to run
2) how long , how many records
3) any error returned
print "\nadding url $addurl to table sajter";
&runsql("insert into ah reason='updated' add=$serverid")
print "->\n"; #end debug info
sub runsql {
my $myquery=$_[0];
my $exitonerror=$_[1] if($_[1]);
my $starttime=time();
unless($dbh){
$sqldebug .= "\nTry SQL: connect to db $hostname, 'uptime_admin'";
$dbh = Mysql->Connect($hostname, 'uptime_admin', 'loguser', 'poopypant
+s') or die "Can not connect to db\nINFO: $sqldebug";
$sqldebug .= "\nConnect OK'";
}
$sqldebug .= "\nTry $myquery";
$runsql_sth = $dbh->query($myquery);
my $endtime=time();
if($runsql_sth){
$numrows=$runsql_sth->affectedrows;
$sqldebug .= " - $numrows rows";
}else{
$errmsg = $dbh->errmsg();
$sqldebug .= "\n -- ERROR -- '$errmsg' ";
if($exitonerror){
die "severe SQL error occurred INFO: $sqldebug";
}
}
$sqldebug .= sprintf " -- Done in %d secs ",$endtime-$starttime;
return $runsql_sth;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.