简体   繁体   中英

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"? eg something like this:

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM