v5:reference:connection:insert_id
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| v5:reference:insert_id [2016/01/13 02:31] – ↷ Page moved from reference:insert_id to v5:reference:insert_id mnewnham | v5:reference:connection:insert_id [2023/06/20 09:40] (current) – [Description] dregad | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| </ | </ | ||
| ===== Description ====== | ===== Description ====== | ||
| - | The function '' | + | The function '' |
| - | 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. | + | 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. | ||
| - | |||
| - | ===== Postgresql / SAP MaxDB ===== | ||
| - | |||
| - | The only drivers that __require__ the optional '' | ||
| ===== 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(' | + | $db->execute(' |
| $lastId = $db-> | $lastId = $db-> | ||
| print $lastId; | print $lastId; | ||
| Line 39: | Line 35: | ||
| * Insert into a different table with auto-increment, | * Insert into a different table with auto-increment, | ||
| */ | */ | ||
| - | $db->Execute(' | + | $db->execute(' |
| $lastId = $db-> | $lastId = $db-> | ||
| print $lastId; | print $lastId; | ||
| Line 46: | Line 42: | ||
| */ | */ | ||
| </ | </ | ||
| + | |||
| + | ===== Oracle Using Emulated Sequences ===== | ||
| + | If you use the emulated sequence function with the [[v5: | ||
| + | |||
| + | <code php> | ||
| + | |||
| + | /* | ||
| + | * Oracle Connection assumed | ||
| + | */ | ||
| + | $sequence = insertId(' | ||
| + | </ | ||
| + | |||
| + | 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 '' | ||
| + | |||
| + | |||
v5/reference/connection/insert_id.1452648665.txt.gz · Last modified: (external edit)
