Home  >  Article  >  Backend Development  >  What should I do if mysql Chinese is garbled under PHP?

What should I do if mysql Chinese is garbled under PHP?

coldplay.xixi
coldplay.xixiOriginal
2020-07-18 11:37:022770browse

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.

What should I do if mysql Chinese is garbled under PHP?

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

What should I do if mysql Chinese is garbled under PHP?

In the [client] tag and [mysqld]

Add:

character_set_server=utf8

What should I do if mysql Chinese is garbled under PHP?

What should I do if mysql Chinese is garbled under PHP?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn