在 iSeries 和可能的其他 db2 平台上,此函数未定义——PHP 致命错误:调用未定义函数 db2_last_insert_id()。
替代方法是使用 IDENTITY_VAL_LOCAL()。
上面的示例变为
<?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')";
$getIdentity = "SELECT IDENTITY_VAL_LOCAL() AS LASTID FROM SYSIBM.SYSDUMMY1";
$stmt = @db2_exec($conn, $createTable);
$stmt = db2_exec($conn, $insertTable);
$stmt = db2_exec($conn, $getIdentity);
$row = db2_fetch_assoc($stmt);
$ret = $row['LASTID'];
if($ret) {
echo "Last Insert ID is : " . $ret . "\n";
} else {
echo "No Last insert ID.\n";
}
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>