Home > database >  The Chinese string error problem of the PHP and database
The Chinese string error problem of the PHP and database

Time:10-06

For web access, using a temporary domain login. The HTML page is always not return data, there is no problem on the local server, modify the login. The PHP code, found that when a user name password mistake can return the correct value, that can be queried from the database, but when the output from the values to be obtained from the database but complains, after trial and error, is found when the output from the database of Chinese string will be an error, and then through the data into the database to verify, js page to PHP page data transmission, and from the PHP page is normal, js and there is no problem between PHP page, but in the database to see is garbled, description in the database code, PHP code between existence question,
4. Change the database encoding, PHP code, js code, HTML coding for all GBK, still not solve the problem, still can get data from the database, but Chinese string in PHP error, the new data in PHP page is correct (echo verified), but the background is still gibberish,
5 to join in PHP page. The following code:
Mysqli_query (" set character set GBK ' '");//read library
Mysqli_query (" set names' GBK '");//write library
Still an error!!!!!! , modified to
Mysql_query (" set character set GBK ' '");//read library
Mysql_query (" set names' GBK '");//write library
Or wrong!!!!!!!!!!!!!!!!
Think of ajax set up to send data in the format as utf8, although feel transmission between Taiwan before and after there is no problem, or trying to modified, xmlHttp. SetRequestHeader (' the content-type ', 'application/x - WWW - form - urlencoded; GBK charset=');
No eggs, still wrong!!!!!!!!!!!!!!!!!!!
Is really no way to ah!!!!!

CodePudding user response:

Years of bloody lesson is all to utf8 and never to GB, as you know, the ajax use utf8 alone can bring a lot of trouble brought before and after the GB transcoding,
1, first the database, data table all set utf8;
2, the PHP backend archived into no BOM utf8 text file itself, and in the beginning of writing a @ header (" content-type: text/HTML. charset=utf-8");
Have both back-end it should be OK, don't use a mysql_query,
If you must show with GB code, front-end HTML then only transcoding only here

CodePudding user response:

UTF8 also has an error, with a system of SugarCRM, + PHP, and Mysql character UTF8, large probability complains when inserted data
  • Related