The example of this article tells the PHP query MSSQL garbled resolution method. Share to everyone for your reference. The specific analysis is as follows:
In the PHP connection MSSQL query out of all is garbled, this problem I know according to experience is coding problem, below to give you a summary of the solution.
method One, modify php.ini file , of course, according to your page situation to set or can be UTF-8 encoded, the code is as follows:
Copy Code code as follows:
; mssql.charset = "Iso-8859-1"
Mssql.charset = "GBK"
method Two, direct conversion in the program , the code is as follows:
Copy Code code as follows:
Iconv (' GB2312 ', ' UTF-8 ', $data)
method Three, use ADO connection to set up the code on the connection, as follows:
Copy Code code as follows:
$conn = new COM ("ADODB. Connection ", NULL, Cp_utf8) or Die (" Cannot start ADO ");
PHP Example , the code is as follows:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8″>
<body>
<?php
Print ("The next line generates an error.www.jb51.net<br>");
Printaline ("please?");
Print ("This won't be displayed due to the above error.");
?>
<?php
$conn = new COM ("ADODB. Connection ", NULL, Cp_utf8) or Die (" Cannot start ADO ");
How Access databases are 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 Query 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>
Summary:
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>
I hope this article will help you with your PHP program design.