pdo catch and output mysql errors

后端 未结 3 468
时光说笑
时光说笑 2021-02-07 20:52

Still trying to get my head around pdo.

I have an insert statement that is executed with pdo. insert works great however if there is an error I would like it displayed t

3条回答
  •  爱一瞬间的悲伤
    2021-02-07 21:14

    By default PDO is not in a state that will display errors. you need to provide the following in your DB connection

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

    More info can be seen Here

提交回复
热议问题