Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Welcome to the Monastery
 
PerlMonks  

Re: CGI Help Guide

by marow (Initiate)
on Sep 03, 2001 at 19:55 UTC ( [id://109928]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to The CGI Help Guide

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; }

Replies are listed 'Best First'.
Re (tilly) 2: CGI Help Guide
by tilly (Archbishop) on Sep 03, 2001 at 20:21 UTC
    You will find your code easier to read if you pick a consistent indentation style and stick to it. What exactly you pick, hanging vs inline braces, etc doesn't so much matter as long as the indent is in the range 2-4 spaces and the style is consistent. If you do that then it is possible to see the logical structure of the code at a glance, which greatly simplifies understanding it.

    Also the better way to do the above is to have a logging function that you pass messages to. By default it would do nothing, but turn on a flag and you get a useful debugging trace out...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109928]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.