PHP PDO: Displaying errors

前端 未结 4 2043
长情又很酷
长情又很酷 2021-01-21 11:49

Do I need to use the try and catch block to display errors with PHP\'s PDO extension?

For example, with mysql you can usally do something like:

if ( ! $q         


        
4条回答
  •  无人共我
    2021-01-21 12:38

    If you don't want to use a try catch statement, you still can use this kind of code :

    $query = $db->prepare("SELECT * FROM table");
    if(!$query->execute()) {
       print_r($query->errorInfo());
    }
    

提交回复
热议问题