Php will connect to the mysql database with garbled characters, which is generally only available in Chinese text, but not in English, because the default connection to mysql is utf8. If your page and database code are inconsistent, it is possible that
Php will connect to the mysql database with garbled characters, which is generally only available in Chinese text, but not in English, because the default connection to mysql is utf8. If your page and database code are inconsistent, garbled characters may occur.
Solution:The page is gb2312
Mysql_qurey specifies that the database is decoded as "set names gb2312" to prevent Chinese garbled characters.
The page code is uft8: mysql_query ('set NAMES utf8'); // you can SET the link encoding based on the php file encoding, for example:
$ Connection = mysql_connect ($ localhost, $ username, $ password );
Mysql_query ('set NAMES utf8'); // sets the link encoding based on the php file encoding.
Gbk
- Mysql_query ('set NAMES gbk ');
-
- $ Db_selected = mysql_select_db ($ database, $ connection );
- If (! $ Db_selected ){
- Die ('Can't use db: '. mysql_error ());
- }
In this way, the output data will not be garbled. if the data is garbled during storage, try to make the page encoding consistent with the database field encoding.