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

55 lines
1.8 KiB
Plaintext
Raw Normal View History

2017-05-03 17:05:26 +02:00
--TEST--
inserting and retrieving UTF-8 text.
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
2017-05-03 17:05:26 +02:00
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
2017-05-03 17:05:26 +02:00
require_once('MsCommon.inc');
$c = AE\connect();
2017-05-03 17:05:26 +02:00
// test a varchar, nvarchar non max, and nvarchar max
$columns = array(new AE\ColumnMeta('varchar(100)', 'c1'),
new AE\ColumnMeta('nvarchar(100)', 'c2'),
new AE\ColumnMeta('nvarchar(max)', 'c3'));
$stmt = AE\createTable($c, "utf8test", $columns);
if (!$stmt) {
fatalError("Failed to create table 'utf8test'\n");
2017-05-03 17:05:26 +02:00
}
$utf8 = pack('H*', 'efbbbfc5a6c4a5c4afc59d20c790c59f20e1baa120c5a5c499c5a1c5a720e1bb97c69220c399c5a4e282a32d3820c2a2d19be1baa7c599e1bab1c2a2c5a3e1bb81c59520c48fc78ec5a5e1baad');
2017-05-03 17:05:26 +02:00
$params = array(array(&$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')),
array(&$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')),
array(&$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')));
$insertSql = "INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)";
$s = AE\executeQueryParams($c, $insertSql, $params);
2017-05-03 17:05:26 +02:00
$s = AE\executeQuery($c, 'SELECT * FROM utf8test');
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-03 17:05:26 +02:00
}
if (sqlsrv_fetch($s) === false) {
die(print_r(sqlsrv_errors(), true));
2017-05-03 17:05:26 +02:00
}
$u = sqlsrv_get_field($s, 1, SQLSRV_PHPTYPE_STREAM('utf-8'));
if ($u === false) {
2018-01-17 00:47:36 +01:00
die(print_r(sqlsrv_errors(), true));
} else {
$utf8_2 = fread($u, 10000);
if ($utf8 != $utf8_2) {
fatalError("round trip failed");
}
2017-05-03 17:05:26 +02:00
}
dropTable($c, 'utf8test');
2017-05-03 17:05:26 +02:00
echo "Test succeeded\n";
?>
--EXPECT--
Test succeeded