note 96947 modified in ref.mssql by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Mar 2010 15:36:48 +0000 |
| Subject: | note 96947 modified in ref.mssql by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167348@lists.php.net to get a copy of this message | ||
I worked on a project with a MS SQL server 2008 containing data of NVARCHAR type in multiple
languages,
including asian characters. It is a known issue, that the PHP MSSQL functions are not able to
retrieve
unicode data form NVARCHAR or NTEXT data fields.
I spent some time searching for possible solutions and finaly found a work arround, that provides
correct
display of latin and asian fonts from a NVARCHAR field.
Do a SQL query, while you convert the NVARCHAR data first to VARBINARY and then to VARCHAR
SELECT
CONVERT(VARCHAR(MAX),CONVERT(VARBINARY(MAX),nvarchar_col)) AS x
FROM dbo.table
While you fetch the result set in PHP, use the iconv() function to convert the data to unicode
<?php $x = iconv("UCS-2LE","UTF-8",$row['x']); ?>
Now you can ouput the text to UTF-8 encoded page with the correct characters.
This workarround did run on IIS 6.0 with PHP 5.2.6 running as FastCGI.
--was--
I worked on a project with a MS SQL server 2008 containing data of NVARCHAR type in multiple
languages,
including asian characters. It is a known issue, that the PHP MSSQL functions are not able to
retrieve
unicode data form NVARCHAR or NTEXT data fields.
I spent some time searching for possible solutions and finaly found a work arround, that provides
correct
display of latin and asian fonts from a NVARCHAR field.
Do a SQL query, while you convert the NVARCHAR data first to VARBINARY and then to VARCHAR
SELECT
CONVERT(VARCHAR(MAX),CONVERT(VARBINARY(MAX),nvarchar_col)) AS x
FROM dbo.table
While you fetch the result set in PHP, use the iconv() function to convert the data to unicode
$x = iconv("UCS-2LE","UTF-8",$row['x']);
Now you can ouput the text to UTF-8 encoded page with the correct characters.
This workarround did run on IIS 6.0 with PHP 5.2.6 running as FastCGI.
http://php.net/manual/en/ref.mssql.php