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

coldplay.xixi
Release: 2023-03-02 14:02:01
Original
2616 people have browsed it

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]);
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template