Solutions to Chinese garbled characters when connecting to mssql in php: 1. Use mssql to force-convert the output data, and only need to convert Chinese characters; 2. Use the latest Microsoft extension sqlsrv driver for php.
Solution to php connection mssql Chinese garbled code:
Cause of garbled code
As long as you use It is the mssql that comes with PHP, and the encoding format of the read data must be gbk. This is because mssql itself only has gbk encoding and cannot define
Solution
1. Use mssql
to force the output data to be converted when outputting. Only Chinese characters need to be converted, and numbers do not need to be converted.
while($row = mssql_fetch_row($result)){ echo iconv('GB2312','UTF-8',$row[0]); }
2. Use the latest Microsoft extension sqlsrv driver for php
Download this dll and put it in the ext folder of php
Modify php.ini to open this extension
When defining the connection, you can specify the encoding as utf-8
Related learning recommendations : PHP programming from entry to proficiency
The above is the detailed content of What to do if php connects to mssql with Chinese garbled characters?. For more information, please follow other related articles on the PHP Chinese website!