IBM DB2 함수 목록
PHP Manual

db2_last_insert_id

(PECL ibm_db2 >= 1.7.1)

db2_last_insert_idReturns the auto generated ID of the last insert query that successfully executed on this connection

설명

int db2_last_insert_id ( resource $resource )

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:

인수

resource

A valid connection resource as returned from db2_connect() or db2_pconnect(). The value of this parameter cannot be a statement resource or result set resource.

반환값

Returns the auto generated ID of last insert query that successfully executed on this connection.

예제

Example #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


IBM DB2 함수 목록
PHP Manual