PHP Connection MSSQL display Chinese as garbled

Source: Internet
Author: User
Tags ini mssql mssql client php code mysql database

The PHP connection MSSQL displays Chinese when garbled is mainly because of the coding problem, we just understand one to the database and the page coding unified processing can solve, below a look below.

Because you have been using Windows PHP development, with the MySQL database, and occasionally will encounter the query records garbled, that is because the PHP code does not support the Chinese lead, directly to encode decoding can be solved, so under the Windows platform is relatively easy to solve.

Today, in helping a customer to maintain the operation of MSSQL database under the Liunx, because the site was attacked the reason, has been unable to open the site, toss for a long time, finally connected to MSSQL, today came to try to query, Mody problem!

But out of the record Chinese display is a number or a bunch of black box, this is the typical coding is not right, so look at the next php.ini about MSSQL this piece of configuration, found that there is a configuration "Mssql.charset" This item, I configured "UTF8", successfully resolved garbled.

Because my program page is UTF8 so configured like this, if it is gbk/gb2312 configuration long corresponding coding should be able to solve, of course, encountered such a problem or to see the corresponding situation, here or suggest if you can modify the configuration file as much as possible to modify the configuration file, Because it can 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 the key.
$conn = Sqlsrv_connect ($serverName, $connectionInfo);

Precautions:

Coding is commonly used in UTF8-GENERAL-CI

Not only the table to be unified, to unify the total is everywhere

One is: the type of database, including, database, table, field three should be unified, you can check

The second is: File encoding type, if you use DW or EditPlus can view page encoding, different need to modify

Three is: Access to the database when the setting is set NAMES UTF8;

Four is: Browser display mode, add meta attribute

No matter with gbk,gb2312, this must be unified everywhere, see you lack of which step

Using PHP to operate MSSQL than in the ASP connection MySQL to be simple, so, when the need for MSSQL and MySQL coexist, use PHP to connect the MSSQL to operate the MySQL and the MSSQL is simple and useful. If the ASP is connected to MySQL, you need to install a MySQL driver, The default Windows ODBC is not installed, unfortunately ...

1. At least the MSSQL client is installed on the Web server

2. Open php.ini; Extension=php_mssql.dll before the semicolon removed

If necessary: need to develop extension_dir

3. Recommended use php<=4.0.9<=5.0.3 currently I have not connected successfully over 4.010 and 5.0.3

4. The connection paging of the database can get the corresponding class on the phpe.net

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.