doyrte8419 2009-11-02 15:14
浏览 214
已采纳

PDO mysql:如何知道插入是否成功

I'm using PDO to insert a record (mysql and php)

$stmt->bindParam(':field1', $field1, PDO::PARAM_STR);
$stmt->bindParam(':field2', $field2, PDO::PARAM_STR);
$stmt->execute();

Is there a way to know if it inserted successfully, for example if the record was not inserted because it was a duplicate?

Edit: of course I can look at the database, but I mean programmatic feedback.

  • 写回答

7条回答 默认 最新

  • doupin2013 2009-11-02 15:16
    关注

    PDOStatement->execute() returns true on success. There is also PDOStatement->errorCode() which you can check for errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?