更新时间:2023-11-28 19:43:16
如果出现错误,则PDO会引发一个异常,您可以捕获该异常.用try catch包装您的代码,并且应该捕获所有异常.
If there's an error then PDO will throw an exception which you can catch. Wrap your code with a try catch and that should catch any exceptions.
try {
$rs = $db->prepare('SELECT * FROM foo');
$rs->execute();
$foo = $rs->fetchAll();
} catch (Exception $e) {
echo 'Error: '.$e->getMessage();
}