![]() ![]() |
|
![]() ![]() ![]() ![]() |
|
![]() |
![]() 20.4.53 Comment obtenir l'ID unique de la dernière ligne insérée?
If you insert a record in a table containing a column that has the
You can also retrieve the ID by using the
You can check if an if (mysql_error(&mysql)[0] == 0 && mysql_num_fields(result) == 0 && mysql_insert_id(&mysql) != 0) { used_id = mysql_insert_id(&mysql); }
The most recently generated ID is maintained in the server on a
per-connection basis. It will not be changed by another client. It will not
even be changed if you update another If you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this: INSERT INTO foo (auto,text) VALUES(NULL,'text'); # generate ID by inserting NULL INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text'); # use ID in second table |