如果没有插入,PDO :: execute如何返回true?

时间:2022-09-26 08:47:49

I'm using PDO::prepare() to prepare an INSERT statement. PDO::execute() returns true, and $dbh->lastInsertId() always has the next id, but no row is actually inserted!

我正在使用PDO :: prepare()来准备INSERT语句。 PDO :: execute()返回true,$ dbh-> lastInsertId()总是有下一个id,但实际上没有插入行!

What could be causing this?

可能是什么导致了这个?

2 个解决方案

#1


1  

if $dbh->lastInsertId() returns id from this very insert (i.e. no other inserts were fired), the row was apparently inserted. Just double-check your table. I mean it.

如果$ dbh-> lastInsertId()从这个插入中返回id(即没有触发其他插入),则显然插入了该行。只需仔细检查你的表。我是认真的。

#2


0  

I'm going to stab in the dark here and wager that you didn't run $dbh->commit() afterwards. Without the commit it will roll back the changes once your script ends or the connection is closed.

我打算在黑暗中刺伤,然后打赌你没有运行$ dbh-> commit()。如果没有提交,它将在脚本结束或连接关闭后回滚更改。

See also: Transactions and auto-commit

另请参见:事务和自动提交

#1


1  

if $dbh->lastInsertId() returns id from this very insert (i.e. no other inserts were fired), the row was apparently inserted. Just double-check your table. I mean it.

如果$ dbh-> lastInsertId()从这个插入中返回id(即没有触发其他插入),则显然插入了该行。只需仔细检查你的表。我是认真的。

#2


0  

I'm going to stab in the dark here and wager that you didn't run $dbh->commit() afterwards. Without the commit it will roll back the changes once your script ends or the connection is closed.

我打算在黑暗中刺伤,然后打赌你没有运行$ dbh-> commit()。如果没有提交,它将在脚本结束或连接关闭后回滚更改。

See also: Transactions and auto-commit

另请参见:事务和自动提交