PHP Connection MSSQL display Chinese as garbled

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

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 come out of the record Chinese display is? Or is a bunch of black box, this is typical coding is wrong, 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 into "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 Copy Code

$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 <meta charset=utf-8>
No matter with gbk,gb2312, this must be unified everywhere, see you lack of which step

Use PHP to operate MSSQL than in ASP to connect to MySQL is simple, so, when the need for MSSQL and MySQL coexist, use PHP to connect MSSQL to operate MySQL and MSSQL coexist relatively simple and useful. If ASP is connected to MySQL, Need to install a MySQL driver, the default Windows ODBC is not installed, it is regrettable ...
1. At least one MSSQL client is installed on the Web server
2. Open php.ini; Extension=php_mssql.dll the preceding semicolon to remove the
if necessary: need to make 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 be obtained to 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.