Page 1 of 1

[SOLVED] Capture the database error

Posted: Fri Nov 05, 2004 10:53 am
by ljCharlie
Here's the line.

Code: Select all

$rsInsertCate = mysql_query($query_rsInsert, $myConnection) or die(mysql_error());
Now, when this line generate an error and die, is there a way to capture the error and assign that to a variable? The reason I want to do this is, if a user is uploading or query something from the database and somehow end up with an error, I want to email that error to me so I can verify why the user receive an error from the database.

ljCharlie

Posted: Fri Nov 05, 2004 11:11 am
by markl999

Code: Select all

//using @ to hide the error from the user
$rsInsertCate = @mysql_query($query_rsInsert, $myConnection);
if($rsInsertCate == false){
  //send your email here
  //just add mysql_error() into the message
  $message .= 'The error was: '.mysql_error();
  ....
  .....
   die('Nice error message for the user here.');
}

Posted: Fri Nov 05, 2004 11:20 am
by ljCharlie
Thank you very much! That works!

ljCharlie

Posted: Fri Nov 05, 2004 12:16 pm
by ljCharlie
One quick question. What is the difference between a die and an exit? The reason is, when the code is die, every code in the page stop executing.

ljCharlie

Posted: Fri Nov 05, 2004 12:21 pm
by timvw
[php_man]exit[/php_man]
[php_man]die[/php_man]

Posted: Fri Nov 05, 2004 12:26 pm
by ljCharlie
My question is, what is the difference between die and exit? Are they the same thing?

Posted: Fri Nov 05, 2004 12:29 pm
by timvw
just follow the links, and read:

die
die -- Equivalent to exit()
Description

This language construct is equivalent to exit().
[/b]

Posted: Fri Nov 05, 2004 12:31 pm
by xisle
die() is an alias of exit(), so they are the same