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

89 lines
3 KiB
Plaintext
Raw Normal View History

2017-05-03 18:53:22 +02:00
--TEST--
Test errorInfo when prepare with and without emulate prepare
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
2017-05-03 18:53:22 +02:00
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
2017-05-03 18:53:22 +02:00
try {
2017-10-10 20:34:59 +02:00
// connection with and without column encryption returns different warning since column encryption cannot use emulate prepare
// turn ERRMODE to silent to compare the errorCode in the test
2017-10-11 00:56:41 +02:00
$conn = connect("", array(), PDO::ERRMODE_SILENT);
2017-05-03 18:53:22 +02:00
//drop, create and insert
$tbname = "test_table";
createTable($conn, $tbname, array("c1" => "int", "c2" => "int"));
insertRow($conn, $tbname, array( "c1" => 1, "c2" => 10 ));
insertRow($conn, $tbname, array( "c1" => 2, "c2" => 20 ));
2017-05-03 18:53:22 +02:00
echo "\n****testing with emulate prepare****\n";
// Do not support emulate prepare with Always Encrypted
2017-12-13 02:12:48 +01:00
if (!isAEConnected()) {
$stmt = $conn->prepare("SELECT c2 FROM $tbname WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => true));
} else {
$stmt = $conn->prepare("SELECT c2 FROM $tbname WHERE c1= :int");
}
2017-05-03 18:53:22 +02:00
$int_col = 1;
//bind param with the wrong parameter name to test for errorInfo
$stmt->bindParam(':in', $int_col);
$stmt->execute();
$stmt_error = $stmt->errorInfo();
2017-12-13 02:12:48 +01:00
if (!isAEConnected()) {
if ($stmt_error[0] != "HY093") {
echo "SQLSTATE should be HY093 when Emulate Prepare is true.\n";
print_r($stmt_error);
}
} else {
if ($stmt_error[0] != "07002") {
echo "SQLSTATE should be 07002 for syntax error in a parameterized query.\n";
print_r($stmt_error);
}
}
$conn_error = $conn->errorInfo();
if ($conn_error[0] != "00000") {
echo "Connection error SQLSTATE should be 00000.\n";
print_r($conn_error);
}
2017-05-03 18:53:22 +02:00
echo "\n****testing without emulate prepare****\n";
$stmt2 = $conn->prepare("SELECT c2 FROM $tbname WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => false));
2017-05-03 18:53:22 +02:00
$int_col = 2;
//bind param with the wrong parameter name to test for errorInfo
$stmt2->bindParam(':it', $int_col);
$stmt2->execute();
2017-05-03 18:53:22 +02:00
$stmt_error = $stmt2->errorInfo();
if ($stmt_error[0] != "07002") {
echo "SQLSTATE should be 07002 for syntax error in a parameterized query.\n";
print_r($stmt_error);
}
2017-05-03 18:53:22 +02:00
$conn_error = $conn->errorInfo();
if ($conn_error[0] != "00000") {
echo "Connection error SQLSTATE should be 00000.\n";
print_r($conn_error);
}
2017-05-03 18:53:22 +02:00
dropTable($conn, $tbname);
unset($stmt);
unset($stmt2);
unset($conn);
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
2017-05-03 18:53:22 +02:00
?>
--EXPECTREGEX--
\*\*\*\*testing with emulate prepare\*\*\*\*
Warning: PDOStatement::(bindParam|execute)\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+
2017-05-03 18:53:22 +02:00
\*\*\*\*testing without emulate prepare\*\*\*\*
2017-10-10 20:34:59 +02:00
Warning: PDOStatement::bindParam\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+