D. Rattansingh
D. Rattansingh

Reputation: 1669

execute multiple statements if mysql_query fails

$query = sprintf("select * from sometable;");
$result = mysql_query($query) or die (mysql_error());

modified to:

$query = sprintf("select * from sometable;");
$result = mysql_query($query) or $DBError=true;

Now I want to execute 2 statements if the query fails, is this possible using the "short above"? e.g. something like this:

$query = sprintf("select * from sometable;");
$result = mysql_query($query) or {$DBError=true; $ErrorCode=0;}

Upvotes: 1

Views: 70

Answers (1)

wazelin
wazelin

Reputation: 751

You can simply use conditional statement like:

$result = mysql_query($query);
if (!$result) {
 $DBError = true;
 $ErrorCode = 0;
}

By the way. mysql_ extension is deprecated. You should use PDO.

Upvotes: 2

Related Questions