PDO lastInsertId不适用于交易吗? [英] PDO lastInsertId does not work on transactions?

查看:86
本文介绍了PDO lastInsertId不适用于交易吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次在MySQL中使用PDO,此刻只是在玩它.

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->dbh->beginTransaction();
// $sql query ran
$this->dbh->commit();

echo $this->dbh->lastInsertId();

lastInsertId()返回0 ...当我在事务外运行相同的查询时,我得到了返回的正确ID号.这里有我想念的东西吗?

lastInsertId() is returning 0...when I run the same query outside of a transaction, I get the proper id number returned. Is there something I am missing here?

推荐答案

在提交transaction

尝试

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

这篇关于PDO lastInsertId不适用于交易吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆