Database Abstraction Layer for PHP

User Tools

Site Tools


This is an old revision of the document!


mixed insert_Id(
optional string $tableName = '',
optional string $columnName = ''


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.

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.

The only drivers that require the optional $table and $column arguments are Postgresql and SAP MaxDB as they support table and column specific insert id numbers.


 * Connection assumed
 * Insert into table with auto-increment column, current highest value 100
$db->Execute('INSERT INTO monkeys (type) value "arctic"');
$lastId = $db->insert_Id();
print $lastId;
 * returns value 101
v5/reference/connection/insert_id.1449619949.txt.gz · Last modified: 2017/04/21 11:34 (external edit)