php-sqlsrv/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt

51 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-05-03 22:09:02 +02:00
--TEST--
PDO Test for PDO::errorCode()
--DESCRIPTION--
Verification of PDO::errorCode()
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
2017-05-03 22:09:02 +02:00
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
try {
$conn1 = connect();
2017-11-03 22:35:16 +01:00
checkError(1, $conn1);
2017-05-03 22:09:02 +02:00
// Prepare test table
$table1 = "Table1";
createTable($conn1, $table1, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "varchar(10)"));
2017-05-03 22:09:02 +02:00
// Check errors when executing SELECT queries
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
checkError(2, $conn1);
checkError(3, $stmt1);
2017-05-03 22:09:02 +02:00
$stmt1->execute();
$stmt2 = &$stmt1;
checkError(4, $stmt1);
2017-05-03 22:09:02 +02:00
$stmt1->closeCursor();
dropTable($conn1, $table1);
checkError(5, $conn1);
2017-05-03 22:09:02 +02:00
// Cleanup
unset($stmt);
unset($conn);
echo "Done\n";
} catch (Exception $e) {
echo $e->getMessage();
2017-05-03 22:09:02 +02:00
}
2017-11-03 22:35:16 +01:00
function checkError($offset, &$obj)
2017-05-03 22:09:02 +02:00
{
$code = $obj->errorCode();
2017-11-03 22:35:16 +01:00
$expected = '00000';
if ($code != $expected && !empty($code)) {
printf("[%03d] Expecting error code '%s' got code '%s'\n", $offset, $expected, $code);
2017-05-03 22:09:02 +02:00
}
}
?>
--EXPECT--
Done