PHP connection MSSQL is garbled when displaying Chinese characters _ PHP Tutorial

Source: Internet
Author: User
Tags mssql client
PHP connection MSSQL is garbled when it displays Chinese characters. PHP connection MSSQL displays garbled characters when displaying Chinese characters. PHP connection MSSQL displays garbled characters mainly because of encoding problems, we only need to know how to process the database and page encoding in a unified manner, so that PHP can connect MSSQL to display garbled characters in Chinese.

When using PHP to connect MSSQL to display Chinese characters, garbled characters are mainly caused by encoding problems. we only need to know how to handle the encoding of databases and pages in a unified manner. let's take a look at the following.

Because I have been using PHP development in windows, using mysql databases, and occasionally encountering garbled characters in query records, it is because php encoding does not support Chinese characters, it can be directly decoded, so it is easier to solve in windows.

Today, I am helping a customer maintain the mssql database under liunx. due to the attack on the site, I have been unable to open the site. after a long time, I finally connected to mssql, let's try the query today. what's the problem!

What is the Chinese display of the records? Number or a bunch of black boxes. this is a typical incorrect code, so I checked the php. this configuration item of ini about mssql is found to be "mssql. charset "is configured as" utf8 "and garbled characters are successfully resolved.

Because my program page uses utf8, it should be configured as follows. if it is GBK/GB2312, it should be able to solve the problem by configuring the corresponding encoding length, of course, we still need to look at the corresponding situation when encountering such a problem. we recommend that you modify the configuration file as much as possible, because this will solve the problem once and for all.

Example

The code is as follows:

$ ServerName = "127.0.0.1, 1433 ";
$ ConnectionInfo = array ("UID" => "sa ",
"PWD" => "123456 ",
"Database" => "NopCommerce ",
"CharacterSet" => "UTF-8"); // This line is important
$ Conn = sqlsrv_connect ($ serverName, $ connectionInfo );

Note:

Coding commonly used is utf8-general-ci

Not only tables must be unified, but a total of four tables must be unified.

First, the database types, including databases, tables, and fields, must be unified. check the fields.

Second, the file encoding type. if you use dw or editplus, you can view the page encoding.

Third, set NAMES utf8 when accessing the database;

4. add the meta attribute in the browser display mode.

No matter how GBK or GB2312 is used, the steps must be unified.

Using PHP to operate MSSQL is easier than connecting to MYSQL in ASP. Therefore, when MSSQL and MYSQL are required to coexist, it is easier to use PHP to connect MSSQL to operate the coexistence of MYSQL and MSSQL. if ASP is used to connect to MYSQL, you need to install a MYSQL driver. by default, ODBC in windows is not installed. sorry...

1. install at least mssql client on the web server

2. open php. ini and remove the semicolon before extension = php_mssql.dll.

Required: extension_dir

3. we recommend that you use php <= 4.0.9 <= 5.0.3. Currently, I have not successfully connected php 4.010 or 5.0.3.

4. you can go to phpe.net to obtain the corresponding class on the database connection page.

When Microsoft PHP connects to MSSQL to display Chinese characters, garbled characters are mainly caused by encoding problems. we only need to know how to process the database and page encoding in a unified manner...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.