[php-src] Issue #9498: unicode string corruption when using PDO_ODBC with FreeTDS 1.3.6 and MS SQL Server 2016
| From: | jnahmias | Date: | Wed, 07 Sep 2022 15:43:10 +0000 |
| Subject: | [php-src] Issue #9498: unicode string corruption when using PDO_ODBC with FreeTDS 1.3.6 and MS SQL Server 2016 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242373@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9498
Author: jnahmias
### Description
The following code:
```php
<?php
// setup database connection
$u = getenv('DB_USERNAME');
$p = getenv('DB_PASSWORD');
$dsn = 'odbc:testUTF8';
$db = new \PDO($dsn, $u, $p);
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$constant_tests = [
"SELECT CAST(0x72006f017e016f007600fd00 AS nvarchar(10)) AS
pink_in_czech_binary_encoded_utf16;",
"SELECT CAST(0x6b26 AS nvarchar(3)) AS Beamed_Eighth_Notes_binary_encoded_utf16;",
"SELECT NCHAR(0x266b) AS Beamed_Eighth_Notes_nchar;",
"SELECT N'♫' AS Beamed_Eighth_Notes_unicode_string_constant;",
"SELECT N'růžový' AS pink_in_czech_unicode_string_constant;",
];
foreach($constant_tests as $t) {
fwrite(STDERR, "Running query '$t'...\n");
var_dump($db->query($t, \PDO::FETCH_ASSOC)->fetchAll());
}
```
Resulted in this output:
```
Running query 'SELECT CAST(0x72006f017e016f007600fd00 AS nvarchar(10)) AS
pink_in_czech_binary_encoded_utf16;'...
array(1) {
[0]=>
array(1) {
["pink_in_czech_binary_encoded_utf16"]=>
string(9) "růžový"
}
}
Running query 'SELECT CAST(0x6b26 AS nvarchar(3)) AS
Beamed_Eighth_Notes_binary_encoded_utf16;'...
array(1) {
[0]=>
array(1) {
["Beamed_Eighth_Notes_binary_encoded_utf16"]=>
string(3) "♫"
}
}
Running query 'SELECT NCHAR(0x266b) AS Beamed_Eighth_Notes_nchar;'...
array(1) {
[0]=>
array(1) {
["Beamed_Eighth_Notes_nchar"]=>
string(3) "▒▒"
}
}
Running query 'SELECT N'♫' AS Beamed_Eighth_Notes_unicode_string_constant;'...
array(1) {
[0]=>
array(1) {
["Beamed_Eighth_Notes_unicode_string_constant"]=>
string(3) "▒▒"
}
}
Running query 'SELECT N'růžový' AS pink_in_czech_unicode_string_constant;'...
array(1) {
[0]=>
array(1) {
["pink_in_czech_unicode_string_constant"]=>
string(9) "růžo"
}
}
```
But I expected this output instead:
```
Running query 'SELECT CAST(0x72006f017e016f007600fd00 AS nvarchar(10)) AS
pink_in_czech_binary_encoded_utf16;'...
array(1) {
[0]=>
array(1) {
["pink_in_czech_binary_encoded_utf16"]=>
string(9) "růžový"
}
}
Running query 'SELECT CAST(0x6b26 AS nvarchar(3)) AS
Beamed_Eighth_Notes_binary_encoded_utf16;'...
array(1) {
[0]=>
array(1) {
["Beamed_Eighth_Notes_binary_encoded_utf16"]=>
string(3) "♫"
}
}
Running query 'SELECT NCHAR(0x266b) AS Beamed_Eighth_Notes_nchar;'...
array(1) {
[0]=>
array(1) {
["Beamed_Eighth_Notes_nchar"]=>
string(3) "♫"
}
}
Running query 'SELECT N'♫' AS Beamed_Eighth_Notes_unicode_string_constant;'...
array(1) {
[0]=>
array(1) {
["Beamed_Eighth_Notes_unicode_string_constant"]=>
string(3) "♫"
}
}
Running query 'SELECT N'růžový' AS pink_in_czech_unicode_string_constant;'...
array(1) {
[0]=>
array(1) {
["pink_in_czech_unicode_string_constant"]=>
string(9) "růžový"
}
}
```
### PHP Version
PHP 8.1.7
### Operating System
Debian GNU/Linux testing/bookworm/unstable