mysql is a very commonly used data database in our projects.
But because we need to save Chinese characters in the database, we often encounter database garbled characters. The following will introduce how to completely solve the problem of Chinese garbled characters in the database.
Database execution
SHOW VARIABLES LIKE '%char%'
See that the character sets are all latin1
Set the character set when creating databases and tables to avoid Chinese garbled characters:
Create database
CREATE DATABASE test CHARACTER SET utf8 COLLATE utf8_general_ci;
--Pay attention to the last three The words are underlined. The value given for each option is not preceded by an equal sign; there is also no comma between the first option and the second option.
Create table
CREATE TABLE cartoon( name varchar(20), sex varchar(20), age varchar(20), country varchar(20) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Once these settings are set, there will basically be no problems.
INSERT INTO `cartoon` VALUES('校长','男','54','中国');
Set the MySQL my.ini file
respectively in the [client] tag And [mysqld]
Add: character_set_server=utf8
## For more PHP related knowledge, please visitPHP Chinese website !
The above is the detailed content of php mysql Chinese garbled code. For more information, please follow other related articles on the PHP Chinese website!