Gossamer Forum
Home : General : Databases and SQL :

How do i display sql errors?

Quote Reply
How do i display sql errors?
Ive got a perl script that loops and updates a mysql database as it loops with variables in the sql statement. This is the exact statement below

my $sql_update = "UPDATE members_rankings SET members_rankings.name = '$FORM{$newname}', members_rankings.regno = '$FORM{$newregno}', members_rankings.rank1 = '$FORM{$newrank1}', members_rankings.rank2 = '$FORM{$newrank2}', members_rankings.regexpireday = $FORM{$newregexpireday}, members_rankings.regexpiremonth = $FORM{$newregexpiremonth}, members_rankings.regexpireyear = $FORM{$newregexpireyear}, members_rankings.profile = $FORM{$newprofile}, members_rankings.profileloc = '$FORM{$newprofileloc}', members_rankings.club = $FORM{$newclub} WHERE (((members_rankings.memid)=$count))";



The script wont run. it wont give any errors neither, it just sits on a white blank screen saying its done. Theres obviously an error that halts the damn script. How do i find out what the error is? i have no access to error logs.
Quote Reply
Re: [TheIceman] How do i display sql errors? In reply to
I assume you are using DBI?

http://search.cpan.org/...30/DBI.pm#RaiseError
Quote Reply
Re: [Paul] How do i display sql errors? In reply to
well thats confused me now. And yeah im using DBI. i couldnt make anything outta that reading i did there. Can ya give an example of using it?

Ive got these 2 lines just after the above sql statement but they dont do nuthin, the script halts on errors and displays nothing. Is there suppose to be another funtion or something i need to use with these below lines to print the error?

my $sth = $dbh->prepare($sql_update) || die "Could not prepare: " . $dbh->errstr();
$sth->execute() || die "Could not execute: " . $dbh->errstr();
Quote Reply
Re: [TheIceman] How do i display sql errors? In reply to
I always use DBI->errstr and $DBI::errstr and they seem to work.

RaiseError goes inside DBI->connect()
Quote Reply
Re: [Paul] How do i display sql errors? In reply to
where about it go in it? i got this inside the connect string.

$dbh = DBI->connect($dsn, $username, $password);

i think im a n00b to mysql with perl.

I got the following piece of code that works i think. How would it make it so if there was an error in the sql string make it display the error and not a blank screen? i cant workout where to put anything.


#!/usr/bin/perl
use DBI;
my $dbh = DBI->connect($dsn, $username, $password);
my $sql_maxmembers = "SELECT Max(members_rankings.memid) AS mems FROM members_rankings";
my $sth = $dbh->prepare($sql_maxmembers) || die "Could not prepare: " . $dbh->errstr();
$sth->execute() || die "Could not execute: " . $dbh->errstr();
my $hashref = $sth->fetchrow_hashref();
$members = $hashref->{'mems'};
$sth->finish();
$dbh->disconnect();
Quote Reply
Re: [TheIceman] How do i display sql errors? In reply to
anyone?
Quote Reply
Re: [TheIceman] How do i display sql errors? In reply to
anyone??
Quote Reply
Re: [TheIceman] How do i display sql errors? In reply to
The problem is the program is die'ing because RaiseError is on. You either need to capture the error, or tell DBI not to die. Try adding:

use CGI::Carp qw/fatalsToBrowser/;

and that will catch any fatal errors and display them to the browser.

Cheers,

Alex
--
Gossamer Threads Inc.