How to view query error in PDO PHP

后端 未结 5 2050
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 08:32
try {
    $db = new PDO(\"mysql:host=\".HOST.\";dbname=\".DB, USER, PW);
    $st = $db->prepare(\"SELECT * FROM c6ode\");
}
catch (PDOException $e){
    echo $e-&         


        
5条回答
  •  孤街浪徒
    2020-11-22 09:32

    I'm guessing that your complaint is that the exception is not firing. PDO is most likely configured to not throw exceptions. Enable them with this:

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    

提交回复
热议问题