PHP query MSSQL appearance question mark (Chinese garbled) solution

Source: Internet
Author: User
Tags mssql access database

Method One, modify the php.ini file (of course depending on your page situation to set or can be Utf-8 code.)

The code is as follows Copy Code

; mssql.charset = "Iso-8859-1"
Mssql.charset = "GBK"

Method two, direct program conversion

The code is as follows Copy Code

Iconv (' GB2312 ', ' UTF-8 ', $data)

Method III, using ADO connection to set the encoding on connection

$conn = new COM ("ADODB. Connection ", NULL, Cp_utf8) or Die (" Cannot start ADO ");

Example

The code is as follows Copy Code
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8″>
<body>
<?php
//print ("The next line generates a error.www.111cn.net<br>");
//printaline ("please?");
//print ("This won't be is displayed due to the above error.");
?>

<?php

• $conn = new COM ("ADODB. Connection ", NULL, Cp_utf8) or Die (" Cannot start ADO ");
How the//access database is opened
//$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};D atabase=sugarcrm_db; Uid=sa; pwd=123456; ");
//execute queries and output data
• $rs = $conn->execute (' SELECT * from accounts ') or Die ("error Query");
?>
<table border= "1″>
<tr><th>id</th><th>title</th>
</tr>
<?php
while (! $rs->eof) {
echo ' <tr> ';
echo ' <td> '. $rs->fields[' id ']->value. ' </td> ';
echo ' <td> '. $rs->fields[' name ']->value. ' </td> ';
echo ' </tr> ';
• $rs->movenext ();
•}
?>
</table>
<?php
//Releasing Resources
• $rs->close ();
• $conn->close ();
• $rs = null;
• $conn = null;

?>
</body>

Summarize

One is: Database type, including, database, table, field three to unify, you can check the
Two is: File encoding type, if you use DW or EditPlus can view page encoding, different need to modify the
Three is: access to the database when the set NAMES UTF8 ;
Four: Browser display mode, add meta attribute <meta charset=utf-8>

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.