Query: db2_last_insert_id
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
DB2_LAST_INSERT_ID(3) 1 DB2_LAST_INSERT_ID(3) db2_last_insert_id - Returns the auto generated ID of the last insert query that successfully executed on this connectionSYNOPSISstring db2_last_insert_id (resource $resource)DESCRIPTIONReturns the auto generated ID of the last insert query that successfully executed on this connection. The result of this function is not affected by any of the following: o A single row INSERT statement with a VALUES clause for a table without an identity column. o A multiple row INSERT statement with a VALUES clause. o An INSERT statement with a fullselect. o A ROLLBACK TO SAVEPOINT statement.PARAMETERSo $resource - A valid connection resource as returned from db2_connect(3) or db2_pconnect(3). The value of this parameter cannot be a state- ment resource or result set resource.RETURN VALUESReturns the auto generated ID of last insert query that successfully executed on this connection.EXAMPLESExample #1 A db2_last_insert_id(3) example The following example shows how to return the auto generated ID of last insert query that successfully executed on this connection. <?php $database = "SAMPLE"; $user = "db2inst1"; $password = "ibmdb2"; $conn = db2_connect($database, $user, $password); if($conn) { $createTable = "CREATE TABLE lastInsertID (id integer GENERATED BY DEFAULT AS IDENTITY, name varchar(20))"; $insertTable = "INSERT INTO lastInsertID (name) VALUES ('Temp Name')"; $stmt = @db2_exec($conn, $createTable); /* Checking for single row inserted. */ $stmt = db2_exec($conn, $insertTable); $ret = db2_last_insert_id($conn); if($ret) { echo "Last Insert ID is : " . $ret . " "; } else { echo "No Last insert ID. "; } db2_close($conn); } else { echo "Connection failed."; } ?> The above example will output: Last Insert ID is : 1 PHP Documentation Group DB2_LAST_INSERT_ID(3)