JohnSmith JohnSmith - 5 months ago 8
SQL Question

How to check if a MySQL query using the legacy API was successful?

How do I check if a MySQL query is successful other than using

die()


I'm trying to achieve...

mysql_query($query);

if(success){
//move file
}
else if(fail){
//display error
}

Answer

This is the first example in the manual page for mysql_query:

$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
    die('Invalid query: ' . mysql_error());
}

If you wish to use something other than die, then I'd suggest trigger_error.

Comments