PDO lastInsertId does not work on transactions?

后端 未结 1 1637
春和景丽
春和景丽 2021-02-12 22:46

I am using PDO for the first time with MySQL, just playing with it at the moment.

So far when I try to do an insert wrapped in transactions...

$this-&         


        
1条回答
  •  故里飘歌
    2021-02-12 23:23

    You have to ask for the lastInsertId() before you commit a transaction

    Try

    $this->dbh->beginTransaction();
    // $sql query ran
    echo $this->dbh->lastInsertId();
    $this->dbh->commit();
    

    0 讨论(0)
提交回复
热议问题