php-sqlsrv/test/functional/sqlsrv/test_error_encoding.phpt

60 lines
1.4 KiB
Plaintext
Raw Normal View History

2017-05-04 18:16:29 +02:00
--TEST--
Encoding of sqlsrv errors
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
function verifyErrorContents()
{
require_once('MsCommon.inc');
$error = sqlsrv_errors()[0];
if ($error['SQLSTATE'] !== '42S22') {
echo "Expected SQLSTATE 42S22\n";
var_dump($error);
}
// The error message is different when testing against Azure DB / Data Warehouse
// Use wildcard patterns for matching
if (isSQLAzure()) {
$expected = "*Invalid column name [\"']BadColumn[\"']\.";
} else {
$expected = "*Ungültiger Spaltenname [\"']BadColumn[\"']\.";
}
2017-05-04 18:16:29 +02:00
if (!fnmatch($expected, $error['message'])) {
echo "Expected to find $expected in the error message\n";
var_dump($error);
}
}
require_once('MsSetup.inc');
2017-05-04 18:16:29 +02:00
$connectionOptions = array('UID' => $userName, 'PWD' => $userPassword, 'CharacterSet' => 'UTF-8');
$conn = sqlsrv_connect($server, $connectionOptions);
if (!$conn) {
die(print_r(sqlsrv_errors(), true));
2017-05-04 18:16:29 +02:00
}
2017-05-04 18:16:29 +02:00
$stmt = sqlsrv_query($conn, "SET LANGUAGE German");
if (!$stmt) {
2017-05-04 18:16:29 +02:00
print_r(sqlsrv_errors());
exit;
}
sqlsrv_free_stmt($stmt);
2017-05-04 18:16:29 +02:00
$stmt = sqlsrv_query($conn, "select *, BadColumn from sys.syslanguages");
if ($stmt) {
echo 'This should have failed!\n';
2017-05-04 18:16:29 +02:00
sqlsrv_free_stmt($stmt);
} else {
verifyErrorContents();
2017-05-04 18:16:29 +02:00
}
2017-05-04 18:16:29 +02:00
sqlsrv_close($conn);
echo "Done\n";
2017-05-04 18:16:29 +02:00
?>
--EXPECT--
Done