Inserting Unicode characters with PHP -> ODBC -> MS SQL?

徘徊边缘 提交于 2019-12-01 18:07:32

问题


I have the following code:

$sql = "update tbl_test set category = N'resumé';

echo $sql;

$rs=odbc_exec($conn,$sql);

Where $conn is a DSN ODBC connection to an MSSQL Server. The problem seems to be that somewhere between PHP and MySQL (Maybe ODBC?) unicode characters are converted to junk. If I copy paste exactly what the echo says directly into Enterprise Manager, it inserts into MS SQL fine. If I run the code however, it always goes into MSSSQL as resumé . Any idea what I'm missing here?


回答1:


The problem was not ODBC, but PHP... solution was to use utf8_decode() on the strings returned from the database.




回答2:


If you are on Windows and running PHP 5.3, using PDO_ODBC with SQL Native Client, and your input text is UTF-8, this should just work automatically.




回答3:


I would tread carefully here. In the past, when dealing with SQL Server and PHP integration, I have encountered cases where SQL Server uses between 3 and 5 times as much storage space as is actually needed for Unicode characters. Depending on how you connect to the database and how the data is encoded. My understanding is that MSFT is working on a new driver (or it has possibly been out for a while) that addresses the issue and generally improves PHP integration. With some of the older stacks, you might run into trouble. I recommend looking at the data size in the DB to verify that the connection is not padding your data.

Jacob



来源:https://stackoverflow.com/questions/1230971/inserting-unicode-characters-with-php-odbc-ms-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!