|
| 1 | +--TEST-- |
| 2 | +Confirm that PDO::ATTR_ERRMODE value should be restored whether PDO::lastInsertId() call succeeded or not. |
| 3 | +--SKIPIF-- |
| 4 | +<?php require('skipif_mid-refactor.inc'); ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +require_once("MsCommon_mid-refactor.inc"); |
| 8 | + |
| 9 | +try { |
| 10 | + $conn = connect(); |
| 11 | + |
| 12 | + // create temporary tables |
| 13 | + createTable($conn, "table1", array(new columnMeta("int", "id", "IDENTITY(100,2)"), "val" => "int")); |
| 14 | + createTable($conn, "table2", array(new columnMeta("int", "id", "IDENTITY(200,2)"), "val" => "int")); |
| 15 | + createTable($conn, "table3", array("id" => "int", "val" => "int")); |
| 16 | + |
| 17 | + insertRow($conn, "table1", array("val" => 1), "exec"); |
| 18 | + insertRow($conn, "table2", array("val" => 2), "exec"); |
| 19 | + $conn->lastInsertId(); |
| 20 | + var_dump($conn->getAttribute(PDO::ATTR_ERRMODE)); |
| 21 | + |
| 22 | + insertRow($conn, "table2", array("val" => 3), "exec"); |
| 23 | + insertRow($conn, "table1", array("val" => 4), "exec"); |
| 24 | + $conn->lastInsertId(); |
| 25 | + var_dump($conn->getAttribute(PDO::ATTR_ERRMODE)); |
| 26 | + |
| 27 | + // Should restore original value even if PDO::lastInsertId() failed. |
| 28 | + insertRow($conn, "table3", array("id" => 1, "val" => 1), "exec"); |
| 29 | + $conn->lastInsertId(); |
| 30 | + var_dump($conn->getAttribute(PDO::ATTR_ERRMODE)); |
| 31 | + |
| 32 | + dropTable($conn, "table1"); |
| 33 | + dropTable($conn, "table2"); |
| 34 | + dropTable($conn, "table3"); |
| 35 | + unset($conn); |
| 36 | +} catch (PDOException $e) { |
| 37 | + var_dump($e); |
| 38 | + exit; |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +?> |
| 43 | +--EXPECT-- |
| 44 | +int(2) |
| 45 | +int(2) |
| 46 | +int(2) |
0 commit comments