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

后端 未结 6 1680
[愿得一人]
[愿得一人] 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

    i struggled with this silent insert fail this week. and here's the solution that worked for me. i was not calling commit on the transaction, so the insert was put into the pending state but was never completed on the database - hence no error. this was trickier because the PDR db wrapper in this project is a static class so it doesn't automatically close

    solution: make sure to call commit on the PDO handle after the insert / update / delete actions - or on page close.

    $PDO->exec("COMMIT;");

提交回复
热议问题