Home >Backend Development >PHP Problem >Chinese garbled code in php database
mysql is a very commonly used data database in our projects. However, because we need to save Chinese characters in the database, we often encounter database garbled characters.
1. Set the character set when creating the database and table to avoid 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. There is no equal sign in front of the value given for each option; there is 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('Principal','Male','54','China');
2、 Set the mySQL my.ini file
Add: character_set_server=utf8
# in the [client] tag and [mysqld] respectively.##
The above is the detailed content of Chinese garbled code in php database. For more information, please follow other related articles on the PHP Chinese website!