I have a query like:
$a = $members->prepare("insert into a(name) values(:name) on duplicate key update name = :name");
Then when I do this:
$insert_id = $a->lastInsertId()
If the query successfully inserted the row, it will return the insert identifier, as expected, if it updates the row, it will also return the updated row identifier, as expected (sort of). But if he did not contribute or update anything, because everything was the same, then it just returns 0.
I assume this is a pretty logical default behavior, but there is a way to change it so that it can return the id of the row that it was trying to update, for example, when it really changes something in the row.
Thanks.
John smith
source share