array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.db2-last-insert-id.php', 1 => 'db2_last_insert_id', 2 => 'Returns the auto generated ID of the last insert query that successfully executed on this connection', ), 'up' => array ( 0 => 'ref.ibm-db2.php', 1 => 'Функції IBM DB2', ), 'prev' => array ( 0 => 'function.db2-get-option.php', 1 => 'db2_get_option', ), 'next' => array ( 0 => 'function.db2-lob-read.php', 1 => 'db2_lob_read', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ibm_db2/functions/db2-last-insert-id.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PECL ibm_db2 >= 1.7.1)
db2_last_insert_id — Returns the auto generated ID of the last insert query that successfully executed on this connection
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:
resourceReturns the auto generated ID of last insert query that successfully executed on this connection.
Приклад #1 A db2_last_insert_id() 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 . "\n";
} else {
echo "No Last insert ID.\n";
}
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>Поданий вище приклад виведе:
Last Insert ID is : 1