Bug #80869 [Opn->Csd]: SQL Server: Read NVARCHAR Unicode

From: Date: Thu, 18 Mar 2021 13:30:50 +0000
Subject: Bug #80869 [Opn->Csd]: SQL Server: Read NVARCHAR Unicode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232847@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80869&edit=1

 ID:                 80869
 Updated by:         cmb@php.net
 Reported by:        sergiopaternoster73 at gmail dot com
 Summary:            SQL Server: Read NVARCHAR Unicode
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PDO ODBC
 Operating System:   Ubuntu 18.04 Server
 PHP Version:        8.0.3
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

> How come do I need to specify PDO::ODBC_ATTR_ASSUME_UTF8 ? The
> result is supposed to be a UTF-8.

You do not necessarily need to specify that, but it can help with
some drivers.  See the constant's documentation[1], where i just
updated the last sentence to read:

| If false (the default), character encoding conversion may be
| done by the driver.

Anyhow, great that you figured out a working solution! 

[1] <https://www.php.net/manual/en/ref.pdo-odbc.php#pdo-odbc.constants>


Previous Comments:
------------------------------------------------------------------------
[2021-03-18 08:38:14] sergiopaternoster73 at gmail dot com

Finally, after a while, I discovered that PHP 8 requires ClientCharset = UTF-8 to be specified in
the odbc.ini file in the ODBC connection parameters. PHP 7 doesn't require it.

Thank you for your help. Please, close this issue.

------------------------------------------------------------------------
[2021-03-17 17:17:53] sergiopaternoster73 at gmail dot com

Unfortunately, even with PHP 8.1.0-dev and the latest install for FreeTDS and unixODBC, it
doesn't work. 

Is there anyone who can run a SQL Server query with NVARCHAR columns and see Unicode characters with
PHP 8?

------------------------------------------------------------------------
[2021-03-17 16:10:27] sergiopaternoster73 at gmail dot com

Related To: Bug #80876

------------------------------------------------------------------------
[2021-03-16 16:11:42] sergiopaternoster73 at gmail dot com

I tested it on Windows (PHP 7.2.5 and PHP 8.0.3). 

SELECT NAME FROM TABLE; (NAME is defined as NVARCHAR(200))

They both work *ONLY* if I set the PDO::ODBC_ATTR_ASSUME_UTF8 => true as option. Otherwise, I
will always get an ASCII when I read an NVARCHAR() column.
How come do I need to specify PDO::ODBC_ATTR_ASSUME_UTF8 ? The result is supposed to be a UTF-8.

Thanks for your help

------------------------------------------------------------------------
[2021-03-16 12:26:14] sergiopaternoster73 at gmail dot com

These are the new traces with FreeTDS 1.2 (from 0.9 before).
Now they look more consistent than before. So why the problem persists?

php 7 trace:
https://gist.github.com/capsandiego/18b2cbb5f6f3e518f508c9b16335b513

php 8 trace:
https://gist.github.com/capsandiego/d51367c34d506d37aa6c62b46d71e1b3

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=80869


--
Edit this bug report at https://bugs.php.net/bug.php?id=80869&edit=1


Thread (15 messages)

« previous php.bugs (#232847) next »