Question

I have a customers table with ID (auto_inc), name, ... and customer_code fields. This table has also a "before" trigger, the select one customer code from another table, and set the customer_code field before insert a new record in this table. Works perfectly.

The problem is that when I retrive the lastInsertID() it always return 1 !

I'm using PDO and PHP.

Thanks for any help!

Was it helpful?

Solution

What version of MySQL are you using? Since 5.0.12, the last insert id shouldn't be overwritten by a trigger. But before that version, a trigger could change the value and subsequent queries would see the wrong value.

See http://dev.mysql.com/doc/refman/5.0/en/stored-routines-last-insert-id.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top