2017-05-04 02:09:36 +02:00
|
|
|
--TEST--
|
|
|
|
UTF-8 connection strings
|
|
|
|
--SKIPIF--
|
2019-05-10 01:58:35 +02:00
|
|
|
<?php require('skipif.inc'); ?>
|
2017-05-04 02:09:36 +02:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
require_once('MsSetup.inc');
|
2019-05-11 07:16:46 +02:00
|
|
|
|
|
|
|
// Expected errors
|
|
|
|
$gibberishEncoding = array('IMSSP', '-48', "The encoding 'gibberish' is not a supported encoding for the CharacterSet connection option.");
|
|
|
|
$binaryEncoding = array('IMSSP', '-48', "The encoding 'binary' is not a supported encoding for the CharacterSet connection option.");
|
|
|
|
$utf16Error = array('IMSSP', '-47', "An error occurred translating the connection string to UTF-16: *");
|
|
|
|
$userLoginFailed = array('28000', '18456', "*Login failed for user *");
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
function connect($options=array())
|
|
|
|
{
|
|
|
|
global $server, $uid, $pwd, $databaseName;
|
|
|
|
|
2017-05-04 02:09:36 +02:00
|
|
|
if (!isset($options['UID']) && !isset($options['uid'])) {
|
|
|
|
$options['uid'] = $uid;
|
|
|
|
}
|
|
|
|
if (!isset($options['pwd']) && !isset($options['PWD'])) {
|
|
|
|
$options['pwd'] = $pwd;
|
|
|
|
}
|
|
|
|
if (!isset($options['Database'])) {
|
2017-10-04 23:22:56 +02:00
|
|
|
$options['database'] = $databaseName;
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
|
|
|
return sqlsrv_connect($server, $options);
|
|
|
|
}
|
|
|
|
|
2019-05-11 07:16:46 +02:00
|
|
|
function checkErrors($expectedError)
|
|
|
|
{
|
|
|
|
// On Windows one call returns two identical errors, so just take the first element
|
|
|
|
$error = sqlsrv_errors()[0];
|
|
|
|
if (!fnmatch($expectedError[0], $error[0]) ||
|
|
|
|
!fnmatch($expectedError[1], $error[1]) ||
|
|
|
|
!fnmatch($expectedError[2], $error[2])) {
|
|
|
|
fatalError("Errors do not match!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
|
|
|
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
|
|
|
// test an invalid encoding
|
2017-05-31 00:24:56 +02:00
|
|
|
$c = connect(array( 'CharacterSet' => 'gibberish' ));
|
2017-10-04 23:22:56 +02:00
|
|
|
if ($c !== false) {
|
|
|
|
fatalError("Should have errored on an invalid encoding.");
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2019-05-11 07:16:46 +02:00
|
|
|
checkErrors($gibberishEncoding);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
$c = connect(array( 'CharacterSet' => SQLSRV_ENC_BINARY ));
|
|
|
|
if ($c !== false) {
|
|
|
|
fatalError("Should have errored on an invalid encoding.");
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2019-05-11 07:16:46 +02:00
|
|
|
checkErrors($binaryEncoding);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
$c = connect(array( 'CharacterSet' => SQLSRV_ENC_CHAR ));
|
|
|
|
if ($c === false) {
|
|
|
|
die(print_r(sqlsrv_errors(), true));
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2017-10-04 23:22:56 +02:00
|
|
|
sqlsrv_close($c);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
|
|
|
// test an invalid server name in UTF-8
|
2017-10-04 23:22:56 +02:00
|
|
|
$server_invalid = pack("H*", "ffc0");
|
|
|
|
$c = sqlsrv_connect($server_invalid, array( 'Database' => 'test', 'CharacterSet' => 'utf-8' ));
|
|
|
|
if ($c !== false) {
|
|
|
|
fatalError("sqlsrv_connect(1) should have failed");
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2019-05-11 07:16:46 +02:00
|
|
|
checkErrors($utf16Error);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
|
|
|
// APP has a UTF-8 name
|
2017-10-04 23:22:56 +02:00
|
|
|
$c = connect(array(
|
|
|
|
'App' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
|
2017-05-04 02:09:36 +02:00
|
|
|
'CharacterSet' => 'utf-8' ));
|
2017-10-04 23:22:56 +02:00
|
|
|
if ($c === false) {
|
|
|
|
die(print_r(sqlsrv_errors(), true));
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
$c = connect(array(
|
|
|
|
'UID' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
|
|
|
|
'PWD' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
|
2017-05-04 02:09:36 +02:00
|
|
|
'CharacterSet' => 'utf-8' ));
|
2017-10-04 23:22:56 +02:00
|
|
|
if ($c !== false) {
|
|
|
|
fatalError("sqlsrv_connect(3) should have failed");
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2019-05-11 07:16:46 +02:00
|
|
|
checkErrors($userLoginFailed);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
|
|
|
// invalid UTF-8 in the pwd
|
2017-10-04 23:22:56 +02:00
|
|
|
$c = connect(array(
|
|
|
|
'UID' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
|
|
|
|
'PWD' => pack('H*', 'c59ec6c0d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
|
2017-05-04 02:09:36 +02:00
|
|
|
'CharacterSet' => 'utf-8' ));
|
2017-10-04 23:22:56 +02:00
|
|
|
if ($c !== false) {
|
|
|
|
fatalError("sqlsrv_connect(4) should have failed");
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2019-05-11 07:16:46 +02:00
|
|
|
checkErrors($utf16Error);
|
2017-05-04 02:09:36 +02:00
|
|
|
|
|
|
|
echo "Test succeeded.\n";
|
|
|
|
|
|
|
|
?>
|
2019-05-13 20:15:49 +02:00
|
|
|
--EXPECT--
|
2017-05-04 02:09:36 +02:00
|
|
|
Test succeeded.
|