v5:reference:connection:insert_id
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
reference:insert_id [2015/07/24 20:11] – created mnewnham | v5:reference:connection:insert_id [2017/04/21 11:50] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
<WRAP right box> | <WRAP right box> | ||
== Syntax == | == Syntax == | ||
- | mixed insert_Id() | + | mixed insert_Id( |
+ | optional string $tableName = '', | ||
+ | optional string $columnName = '' | ||
+ | | ||
</ | </ | ||
===== 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. | ||
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 25: | Line 34: | ||
/* | /* | ||
* returns value 101 | * returns value 101 | ||
+ | */ | ||
+ | |||
+ | /* | ||
+ | * Insert into a different table with auto-increment, | ||
+ | */ | ||
+ | $db-> | ||
+ | $lastId = $db-> | ||
+ | print $lastId; | ||
+ | /* | ||
+ | * returns value 51, There is now no way of retrieving the previous last id | ||
*/ | */ | ||
</ | </ |
v5/reference/connection/insert_id.txt · Last modified: 2023/06/20 09:40 by dregad