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 revision Previous revision
Next revision
Previous revision
v5:reference:connection:insert_id [2016/01/13 02:31]
mnewnham ↷ Page moved from reference:insert_id to v5:reference:insert_id
v5:reference:connection:insert_id [2019/07/08 22:20] (current)
mnewnham
Line 14: Line 14:
  
 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.
- 
-===== Postgresql / SAP MaxDB ===== 
- 
-The only drivers that __require__ the optional ''$table'' and ''$column'' arguments are [[v5:database:postgresql]] and [[v5:database:sap_maxdb]] as they support table and column specific insert id numbers. 
  
 ===== Usage ===== ===== Usage =====
Line 29: Line 25:
  * Insert into table with auto-increment column, current highest value 100  * Insert into table with auto-increment column, current highest value 100
  */  */
-$db->Execute('INSERT INTO monkeys (type) value "arctic"');+$db->execute('INSERT INTO monkeys (type) value "arctic"');
 $lastId = $db->insert_Id(); $lastId = $db->insert_Id();
 print $lastId; print $lastId;
Line 39: Line 35:
  * Insert into a different table with auto-increment, current highest value 50.  * Insert into a different table with auto-increment, current highest value 50.
  */  */
-$db->Execute('INSERT INTO pickups (type) value "F150"');+$db->execute('INSERT INTO pickups (type) value "F150"');
 $lastId = $db->insert_Id(); $lastId = $db->insert_Id();
 print $lastId; print $lastId;
Line 46: Line 42:
  */  */
 </code> </code>
 +
 +===== Oracle Using Emulated Sequences =====
 +If you use the emulated sequence function with the [[v5:database:oracle|OCI8]] driver, you __must__ provide the table name in order to retrieve the last sequence. This is because the value is being returned from a table related sequence, not a global insertId instance.
 +
 +<code php>
 +
 +/*
 + * Oracle Connection assumed
 + */
 +$sequence = insertId('some_table');
 +</code>
 +
 +For that reason, the usage rules about a single instance do not apply. However if you are writing cross-database code you should follow those rules.
 +
 +===== Postgresql / SAP MaxDB =====
 +
 +The only drivers that __require__ the optional ''$table'' and ''$column'' arguments are [[v5:database:postgresql]] and [[v5:database:sap_maxdb]] as they support table and column specific insert id numbers.
 +
 +
v5/reference/connection/insert_id.1452648665.txt.gz · Last modified: 2017/04/21 11:34 (external edit)