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>