What should I do if the php link to sqlserver is garbled in Chinese?

coldplay.xixi
Release: 2023-03-02 09:54:01
Original
2779 people have browsed it

Solution to the Chinese garbled code in php link sqlserver: 1. Open the query analyzer of sqlserver2005; 2. Open [php.ini] and configure [mssql.charset = "utf-8"]; 3. In php Add relevant codes to the file; 4. Transcode the input data.

What should I do if the php link to sqlserver is garbled in Chinese?

Solution to Chinese garbled php link to sqlserver:

First, open the query analysis of sqlserver2005 Run the server , code

SELECT  COLLATIONPROPERTY('Chinese_PRC_Stroke_CI_AI_KS_WS', 'CodePage')
Copy after login

, and check the result. "936" is displayed, indicating that the encoding of the database is GBK

. The attached table is as follows:

936 Simplified Chinese GBK

950 Traditional Chinese BIG5

437 United States/Canada English

932 Japanese

949 Korean 8

66 Russian

65001 unicode UFT-8

Second, open php.ini and configure it as follows

mssql.charset = "utf-8"
Copy after login

Remember to restart the server! ! ! ! ! ! !

Third, add the following code in the php file,

<?php
   ……   header("content-Type: text/html; charset=utf-8");
   ……?>
Copy after login

Fourth, transcode the input data

The data table test is as follows:

What should I do if the php link to sqlserver is garbled in Chinese?

The variable submitted by the simulation is type = 'Unicom', and it is transcoded

$type = &#39;联通&#39;;$type = (iconv(&#39;UTF-8&#39;,&#39;GBK&#39;,$type));
Copy after login

sql statement is as follows,

$result= mssql_query("select * from dbo.test where type = &#39;$type&#39; and name = &#39;TOM&#39;", $conn);
Copy after login

Fifth, transcode the query results (the core code is as follows)

$res[&#39;type&#39;] = iconv(&#39;GBK&#39;,&#39;UTF-8&#39;,$result[&#39;type&#39;]);echo $res[&#39;type&#39;];
Copy after login

View the output:

China Unicom

it shows good.

Sixth, change the fifth code as follows:

$res[&#39;stname&#39;] = urlencode(iconv(&#39;GBK&#39;,&#39;UTF-8&#39;,$row[&#39;stname&#39;]));
Copy after login

Then, encapsulate JSON and send it out

echo urldecode(json_encode($res));
Copy after login

Related Learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of What should I do if the php link to sqlserver is garbled in Chinese?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!