Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBI and the silent error approach

Status
Not open for further replies.

jez

Programmer
Apr 24, 2001
370
VN
Hi.

Can anyone see why i do not get any errors from the following perl code.

Code:
my $dbh = DBI->connect ("DBI:mysql:webreq", "webreq", "webreq",{PrintError=> 1, RaiseError => 1}) || die "Can not connect : $DBI::errstr\n";


...

$sth = $dbh->prepare ("$sql") or die ("Can not prepare query : $dbh->errstr<BR>\n<br>");


...
 $sth->execute() or die("ERROR!: " . $sth->errstr);

 if($dbh->errstr){
                print $dbh->errstr;
            }else{
                print "Record stored for ".$session_id ." on local mysql db";
            }

The documentation talks about using DO not EXECUTE, and also eval. I do not see why or how either of those approaches is significantly different to this.
Also adding an EVAL around the execute causes a syntax error.
Also i really don't understand why we have to eval a command to get information. Isn't eval going to add load to the script?

thanks.
 
where are you expecting an error? Should those first || be an or?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I'll try that, but in answer to your question i have problems with the SQL which have died silently, but then getting it to print the SQL and running it on the DB directly, i get an error from the DB.

What i would like is to be told if it cannot connect or for some reason run the SQL.

thanks
 
well forget the || vs or (I have a discussion on here some where comparing them).. check out this page where they are evaling the code in the examples.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Hi all,

I have solved my problem but with much more basic checking functions in the script. I created print points (like breakpoints) to show where the code got to.

It seems that the error was in the SQL, but it was not throwing an error on the sql. So although the problem is now gone, i still am not sure how to do error checking with DBI.

Thanks for all the responses.

Jez
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top