我应该使用mysql_sql_exception在sql查询中获取错误,还是应该使用成员变量$errno和$error?
它们等效吗?
try {
$result = $db->query($query);
} catch (mysqli_sql_exception $e) {
//Error
}
// OR
$result = $db->query($query);
if ($db->errno != 0) {
//Error
}
这取决于您的mysqli错误报告设置。您可以使用mysqli_report()函数更改它们。例如,如果调用mysqli_report(MYSQLI_REPORT_STRICT);
,则会抛出mysqli_sql_exception
以显示错误而不是警告。