Bug #18169: Driver cannot deliver UCS-2 unicode to SQL Server

From: Date: Thu, 04 Jul 2002 22:10:24 +0000
Subject: Bug #18169: Driver cannot deliver UCS-2 unicode to SQL Server
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-13156@lists.php.net to get a copy of this message
From: joesterg@hotmail.com Operating system: Windows 2000 Server PHP version: 4.1.2 PHP Bug Type: MSSQL related Bug description: Driver cannot deliver UCS-2 unicode to SQL Server I have a problem converting UTF-8 (web character encoding) to UCS2 (Microsoft Windows character encoding) using PHP, and storing this in the Microsoft SQL Server 2000 database. My setup is: Windows 2000 Server, with Apache 1.3.24/PHP 4.1.1 and Microsoft SQL Server 2000 Now, as a result of Microsofts Q232580, I will have to do conversion between UTF-8 and UCS-2. For this, I thought I would use the Multibyte String functions. However, this does not seem to work. I am absolutely sure, that I input UTF-8 encoded data into my string, and then I do: $ucs2string=mb_convert_encoding($string,"UCS2","UTF-8"); $sqlStmt="insert into testtbl (tekst) values(N'".($ucs2string)."')"; $rs=$DBCon->Execute($sqlStmt); When I access the database, then I will see something stored, that does not resemble the input at all (most times, I see Japanese/Chinese characters?!??). Furthermore, the insert sometimes comes up with an error, and consequently stores nothing. To me, it seems like either one of these (or both) are flawed: 1. the Multibyte String encoding funtion does not work properly (ie. encoding from UTF-8 to UCS-2 does not happen correctly). 2. The PHP MSSQL driver does not handle unicode data properly, even though the target column in the database is specified as Unicode and N is prepended to the string before insert. This leads me to use ADO (as in the example above), storing UTF-8 encoded data into SQL Server -this is a very short term solution, as data are not sortable in the database (some of it looks like garbage because of the missing encoding). -- Edit bug report at http://bugs.php.net/?id=18169&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=18169&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=18169&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=18169&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=18169&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=18169&r=support Expected behavior: http://bugs.php.net/fix.php?id=18169&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=18169&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=18169&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=18169&r=globals

« previous php.bugs (#13156) next »