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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching Database errors

Status
Not open for further replies.

Haunter

Programmer
Jan 2, 2001
379
US
I am trying to use a database for logon information, but what if my query for the user fails how do I catch the error so I can send a message letting them know they dont have the right user name? I also dont want the query to end the program?

my($user) = $q->param('user');
my($pass ) = $q->param('pass');

&con;#connects to database
$sth=$dbh->prepare (qq{
SELECT pass FROM userdata WHERE user=?
} );
$sth->execute ($user);
$sth->bind_columns (\$pass);
$sth->fetch;
$sth->finish;

&dis#disconnects from database;

ty in advance
 
Try this.

sth=$dbh->prepare (qq{SELECT pass FROM userdata WHERE user=?} );
$sth->execute ($user) || die "$dbh->err: $dbh->errstr\n";
$sth->bind_columns (\$pass);
$sth->fetch;
$sth->finish;


$dbh->err Error Code
$dbh->errstr Error Message
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top