Home  >  Article  >  Backend Development  >  php mysql Chinese garbled code

php mysql Chinese garbled code

angryTom
angryTomOriginal
2019-10-17 14:14:212885browse

php mysql Chinese garbled code

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.

php mysql Chinese garbled code

Database execution

SHOW VARIABLES LIKE '%char%'

See that the character sets are all latin1

php mysql Chinese garbled code

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','中国');

php mysql Chinese garbled code

Set the MySQL my.ini file

php mysql Chinese garbled code

respectively in the [client] tag And [mysqld]

Add: character_set_server=utf8

php mysql Chinese garbled codephp mysql Chinese garbled code

## For more PHP related knowledge, please visit

PHP 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!

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