Home >Backend Development >PHP Problem >What should I do if the php link to sqlserver is garbled in Chinese?
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.
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')
, 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"
Remember to restart the server! ! ! ! ! ! !
Third, add the following code in the php file,
<?php …… header("content-Type: text/html; charset=utf-8"); ……?>
Fourth, transcode the input data
The data table test is as follows:
The variable submitted by the simulation is type = 'Unicom', and it is transcoded
$type = '联通';$type = (iconv('UTF-8','GBK',$type));
sql statement is as follows,
$result= mssql_query("select * from dbo.test where type = '$type' and name = 'TOM'", $conn);
Fifth, transcode the query results (the core code is as follows)
$res['type'] = iconv('GBK','UTF-8',$result['type']);echo $res['type'];
View the output:
China Unicom
it shows good.
Sixth, change the fifth code as follows:
$res['stname'] = urlencode(iconv('GBK','UTF-8',$row['stname']));
Then, encapsulate JSON and send it out
echo urldecode(json_encode($res));
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!