2017-04-03 19:02:26 +02:00
|
|
|
--TEST--
|
|
|
|
Test the PDO::lastInsertId() method.
|
|
|
|
--SKIPIF--
|
2017-10-04 22:16:25 +02:00
|
|
|
<?php require('skipif_mid-refactor.inc'); ?>
|
2017-04-03 19:02:26 +02:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2017-10-04 22:16:25 +02:00
|
|
|
require_once("MsCommon_mid-refactor.inc");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$conn = connect();
|
|
|
|
|
2017-05-02 21:00:53 +02:00
|
|
|
// create temporary tables
|
2017-10-04 22:16:25 +02:00
|
|
|
createTable($conn, "table1", array(new columnMeta("int", "id", "IDENTITY(100,2)"), "val" => "int"));
|
|
|
|
createTable($conn, "table2", array(new columnMeta("int", "id", "IDENTITY(200,2)"), "val" => "int"));
|
|
|
|
createTable($conn, "table3", array("id" => "int", "val" => "int"));
|
|
|
|
|
|
|
|
insertRow($conn, "table1", array("val" => 1), "exec");
|
|
|
|
insertRow($conn, "table2", array("val" => 2), "exec");
|
2017-04-12 20:21:54 +02:00
|
|
|
$id = $conn->lastInsertId();
|
|
|
|
var_dump($id);
|
2017-10-04 22:16:25 +02:00
|
|
|
|
|
|
|
insertRow($conn, "table2", array("val" => 3), "exec");
|
|
|
|
insertRow($conn, "table1", array("val" => 4), "exec");
|
2017-04-12 20:21:54 +02:00
|
|
|
$id = $conn->lastInsertId();
|
|
|
|
var_dump($id);
|
2017-10-04 22:16:25 +02:00
|
|
|
|
2017-04-12 20:21:54 +02:00
|
|
|
// Should return empty string as the table does not have an IDENTITY column.
|
2017-10-04 22:16:25 +02:00
|
|
|
insertRow($conn, "table3", array("id" => 1, "val" => 1), "exec");
|
2017-04-12 20:21:54 +02:00
|
|
|
$id = $conn->lastInsertId();
|
2017-10-04 22:16:25 +02:00
|
|
|
var_dump($id);
|
2017-04-03 19:02:26 +02:00
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
dropTable($conn, "table1");
|
|
|
|
dropTable($conn, "table2");
|
|
|
|
dropTable($conn, "table3");
|
|
|
|
unset($conn);
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
var_dump($e);
|
2017-04-03 19:02:26 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-04 22:16:25 +02:00
|
|
|
?>
|
2021-11-19 01:38:19 +01:00
|
|
|
--EXPECT--
|
|
|
|
string(3) "200"
|
|
|
|
string(3) "102"
|
|
|
|
string(0) ""
|