db2_last_insert_id(3) php man page | unix.com

Man Page: db2_last_insert_id

Operating Environment: php

Section: 3

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 connection

SYNOPSIS
string db2_last_insert_id (resource $resource)
DESCRIPTION
Returns 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.
PARAMETERS
o $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 VALUES
Returns the auto generated ID of last insert query that successfully executed on this connection.
EXAMPLES
Example #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)
Related Man Pages
db2_exec(3) - php
db2_fetch_object(3) - php
db2_last_insert_id(3) - php
sqlsrv_next_result(3) - php
sqlsrv_rows_affected(3) - php
Similar Topics in the Unix Linux Community
How to insert data befor some field in a row of data depending up on values in row
check if the insert statement is using column names
Insert value to db from text file
Insert query with shell variable with AWK
Insert row into empty file...how?