简体   繁体   中英

PHP: mysqli_sql_exception vs mysql $errno and $error

Should I use mysql_sql_exception to get errors in the sql querys or should I use the member variables $errno and $error?

Are they equivalent?

try {
    $result = $db->query($query);
} catch (mysqli_sql_exception $e) {
    //Error
}

// OR

$result = $db->query($query);
if ($db->errno != 0) {
    //Error
}

It depends on your mysqli error reporting settings. You can change them using mysqli_report() function . For example, if you call mysqli_report(MYSQLI_REPORT_STRICT); - the mysqli_sql_exception will be thrown for errors instead of warnings.

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