E
E
Ellik2015-11-17 18:03:03
PHP
Ellik, 2015-11-17 18:03:03

How to return id when updating ON DUPLICATE KEY UPDATE?

Good evening!
There is the following request:

INSERT INTO `group_attributes`
VALUES (NULL, :title)
ON DUPLICATE KEY UPDATE title = :title

Using the PDO function in php lastInsertId, I get the id if a new record is inserted, but the id does not update when it is updated. Please tell me the solution to this problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2015-11-17
@Ellik

ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)
Documentation - dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate...

W
wol_fi, 2015-11-17
@wol_fi

well last insert Id speaks for itself. check the return, if the id has not arrived, pull it out with a query - SELECT id FROM table WHERE title = :title.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question