1
votes

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!

What could be causing this?

2

2 Answers

1
votes

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.

0
votes

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.

See also: Transactions and auto-commit