I am using REPLACE INTO query to insert in to table but after executing query by using mysql_query() function and if I use last_insert_id() it is only giving me 0 value.
why this is happening so? and how can I overcome this behavior.
:Pankaj
I am using REPLACE INTO query to insert in to table but after executing query by using mysql_query() function and if I use last_insert_id() it is only giving me 0 value.
why this is happening so? and how can I overcome this behavior.
:Pankaj
REPLACE INTO
doesn't seem to affect the vaue that can be obtained via last_insert_id()
.
It seems to be the expected behavior, judging from this :
You could try using INSERT INTO ... ON DUPLICATE KEY UPDATE
instead. It accomplishes the same thing as REPLACE INTO
, but in a single server-side operation. REPLACE INTO
can end up causing two operations: delete the old one, insert the new one.
But regardless of the query type, you do have to ensure that the table's primary key is an auto_increment
field. last_insert_id() does not work properly otherwise.