This PDO prepared statement returns false but does not throw an error

后端 未结 6 1727
[愿得一人]
[愿得一人] 2021-02-18 23:09

This code does not throw an error but the query fails, that is, the execute method returns false. How could that be?

require_once(\"Abstracts/DBMana         


        
6条回答
  •  故里飘歌
    2021-02-18 23:26

    Just wanted to add to this, had similar frustrations from the lack of an error message.

    To stop PDO from silently failing, you can set the error mode on the PDO connection.

    $dbh = new PDO();
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    There is also PDO::ERRMODE_WARNING if you want errors but still continue.

提交回复
热议问题