ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:insert_id

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
reference:insert_id [2015/12/12 17:35] mnewnhamreference:insert_id [2015/12/12 17:42] mnewnham
Line 11: Line 11:
 The function ''insert_Id()'' returns the last auto-increment number of __any__ table, generated by an insert on a table with an auto-increment column. If no such insertion has occurred or the database does not support the operation, the function returns false. The function ''insert_Id()'' returns the last auto-increment number of __any__ table, generated by an insert on a table with an auto-increment column. If no such insertion has occurred or the database does not support the operation, the function returns false.
  
-The value retrieved is **connection based**, meaning that each concurrent connection (even if they are associated with the same procedure) has its own instance of the number.+The value retrieved is **connection based**, meaning that each concurrent connection (even if multiple connections are associated with the same procedure) has its own instance of the number.
  
 It is important to remember that there is only a single storage instance for the number, and if one insert statement with an auto-increment number succeeds another, the insert_id value for the second statement will overwrite the value of the first, so retrieve the value of the first before executing the second. It is important to remember that there is only a single storage instance for the number, and if one insert statement with an auto-increment number succeeds another, the insert_id value for the second statement will overwrite the value of the first, so retrieve the value of the first before executing the second.
Line 34: Line 34:
 /* /*
  * returns value 101  * returns value 101
 + */
 +
 +/*
 + * Insert into a different table with auto-increment, current highest value 50.
 + */
 +$db->Execute('INSERT INTO pickups (type) value "F150"');
 +$lastId = $db->insert_Id();
 +print $lastId;
 +/*
 + * returns value 51, There is now no way of retrieving the previous last id
  */  */
 </code> </code>
v5/reference/connection/insert_id.txt · Last modified: 2023/06/20 09:40 by dregad