How to solve mssql garbled query in php? mssql garbled _ PHP Tutorial

Source: Internet
Author: User
Tags php example
The solution for querying mssql in php is garbled, and mssql is garbled. The solution for querying mssql in php is garbled. the example in this article describes the solution for querying mssql in php. Share it with you for your reference. The specific analysis is as follows: the solution of mssql garbled in p php query is mssql garbled.

The example in this article describes how to query mssql in php with garbled code. Share it with you for your reference. The specific analysis is as follows:

When php is connected to mssql, all the queries are garbled characters. I know from experience that this problem is a coding problem. next I will summarize the solution for you.

Method 1: modify the php. ini fileOf course, you can set it to UTF-8 based on your page. the code is as follows:

The code is as follows:

; Mssql. charset = "ISO-8859-1"

Mssql. charset = "GBK"

Method 2: direct conversion in the programThe code is as follows:

The code is as follows:

Iconv ('gb2312', 'utf-8', $ data)

Method 3: use Ado Connection to set encoding during connectionThe code is as follows:

The code is as follows:

$ Conn = new COM ("ADODB. Connection", NULL, CP_UTF8) or die ("Cannot start ADO ");

PHP exampleThe code is as follows:

The code is as follows:



");
// Printaline ("PLEASE? ");
// Print ("This will not be displayed due to the above error .");
?>
<? Php
$ Conn = new COM ("ADODB. Connection", NULL, CP_UTF8) or die ("Cannot start ADO ");
// How to open the access database
// $ Conn-> Open ("Provider = Microsoft. Jet. OLEDB.4.0; Data Source = $ db ");
// $ Conn-> Open ("DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ = $ db ");
$ Conn-> Open ("Driver = {SQL Server}; Server = {192.168.22.40}; Database = sugarcrm_db; UID = sa; PWD = 123456 ;");
// Execute the query and output data
$ Rs = $ conn-> Execute ('select * FROM accounts') or die ("error query ");
?>

Examples in this article describe how to query mssql in php with garbled code. Share it with you for your reference. The specific analysis is as follows: in p...

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.