note 96947 added to ref.mssql
| From: | stephan at towli dot ch | Date: | Wed, 24 Mar 2010 15:25:34 +0000 |
| Subject: | note 96947 added to ref.mssql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167347@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
$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.
----
Server IP: 62.2.182.223
Probable Submitter: 194.204.66.37
----
Manual Page -- http://www.php.net/manual/en/ref.mssql.php
Edit -- https://master.php.net/note/edit/96947
Del: integrated -- https://master.php.net/note/delete/96947/integrated
Del: useless -- https://master.php.net/note/delete/96947/useless
Del: bad code -- https://master.php.net/note/delete/96947/bad+code
Del: spam -- https://master.php.net/note/delete/96947/spam
Del: non-english -- https://master.php.net/note/delete/96947/non-english
Del: in docs -- https://master.php.net/note/delete/96947/in+docs
Del: other reasons-- https://master.php.net/note/delete/96947
Reject -- https://master.php.net/note/reject/96947
Search -- https://master.php.net/manage/user-notes.php