Home >Backend Development >PHP Problem >What should I do if mysql Chinese is garbled under PHP?
Solution to Chinese garbled characters in mysql under php: First set the character set when creating the database and table; then set the [my.ini] file of MySQL and add the statement [character_set_server=utf8] to the tags client and mysqld respectively.
Solution to mysql Chinese garbled characters under php:
Set the character set when creating databases and tables to avoid occurrences Chinese garbled characters
Create database
CREATE DATABASE test CHARACTER SET utf8 COLLATE utf8_general_ci;
--Note that there are underlines between the next three words. For the value given for each option, there is no equal sign in front. ;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
In the [client] tag and [mysqld]
Add:
character_set_server=utf8
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of What should I do if mysql Chinese is garbled under PHP?. For more information, please follow other related articles on the PHP Chinese website!