search
HomeBackend DevelopmentPHP ProblemWhat should I do if the php link to sqlserver is garbled in Chinese?

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

Jul 10, 2020 pm 01:06 PM
phpsqlserverGarbled characters

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')

, 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:

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));

sql statement is as follows,

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

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;];

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;]));

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),