Home  >  Article  >  Backend Development  >  What to do if php connects to mssql with Chinese garbled characters?

What to do if php connects to mssql with Chinese garbled characters?

coldplay.xixi
coldplay.xixiOriginal
2020-07-13 15:11:552566browse

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.

What to do if php connects to mssql with Chinese garbled characters?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn