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

coldplay.xixi
Release: 2023-03-02 17:40:02
Original
2771 people have browsed it

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;
Copy after login

--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;
Copy after login

Once these settings are set, there will basically be no problems.

INSERT INTO `cartoon` VALUES('校长','男','54','中国');
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template