سؤال

I am using PDO to connect to MySQL. When even I add new record to the database and want to know the id of the last record added then I call the lastinsertid() built in PDO. However, this time I am trying to return the last updated record. According to my knowledge PDO::lastInsertId should return the last updated ID as well.

Returns the ID of the last inserted row, or the last value from a sequence object

But in my case it does not return what it should. It returns the value 0.
How can I configure lastinsertid() to return the AUTO_INCREMENT value of the record that was updated by the update query?

هل كانت مفيدة؟

المحلول

I count not find a way to return last updated id. But what I have done is to accomplish what I am looking for is by checking the countRow method as it return the total effected rows.

So I do an update if a record is found then done. if there was no record found I do an insert.

Thanks

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top