PHP Connection MSSQL display Chinese as garbled _php tutorial

Source: Internet
Author: User
Tags mssql

PHP Connection MSSQL display Chinese is garbled


PHP Connection MSSQL Display Chinese is garbled mainly because of the coding problem, we just know a database and page encoding unified processing can be resolved, the following together to see below.

Because the use of PHP in the development of windows, with the MySQL database, and occasionally encounter the query record garbled, that is because the PHP encoding does not support the cause of Chinese, and directly encode and decode it can be resolved, so in the Windows platform is relatively easy to solve.

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

But out of the record Chinese display is the number or is a bunch of black box, which is the typical coding is wrong, so look at the next php.ini about the MSSQL configuration, found that there is a configuration "Mssql.charset" This one, I configured to "UTF8", successfully solve garbled.

Because my program page is UTF8 so configured to this, if it is gbk/gb2312 on the configuration of the corresponding encoding should be able to solve, of course, encountered such a problem or to see the corresponding situation, here is also recommended if you can modify the configuration file as far as possible to modify the configuration file, Because this can solve the problem once and for all.

Example

code as follows

$serverName = "127.0.0.1,1433";
$connectionInfo = Array ("UID" = "sa",
"PWD" = "123456",
"Database" = "Nopcommerce",
"CharacterSet" = "UTF-8"); This line is the point.
$conn = Sqlsrv_connect ($serverName, $connectionInfo);

Precautions:

Coding is commonly used in UTF8-GENERAL-CI

Not only the table to unify, to unify the total common all around

One is: The database type, which includes, database, table, fields are unified three, you can check

The second is: the file encoding type, if you use DW or editplus can see the page encoding, different need to modify

The third is: when accessing the database settings are set NAMES UTF8;

Four: Browser display mode, add meta attribute

No matter with gbk,gb2312, this must be unified everywhere, see you missing a step

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

1. A client with at least MSSQL installed on the Web server

2. Open the php.ini and remove the semicolon in front of the Extension=php_mssql.dll.

It is necessary 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 page of the database can be obtained on the phpe.net to the corresponding class

http://www.bkjia.com/PHPjc/869305.html www.bkjia.com true http://www.bkjia.com/PHPjc/869305.html techarticle PHP Connection MSSQL display Chinese when garbled PHP connection MSSQL display Chinese is garbled mainly because of the coding problem, we just know a database and page encoding unified processing can ...

  • Related Article

    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.