且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确保PDO获取方法的结果为“假".是错误或空结果

更新时间: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();
}