Home  >  Article  >  Backend Development  >  Chinese garbled code in php database

Chinese garbled code in php database

尚
Original
2019-10-28 11:10:432956browse

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.

Chinese garbled code in php database

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');

Chinese garbled code in php database

2、 Set the mySQL my.ini file

Chinese garbled code in php database

Add: character_set_server=utf8

# in the [client] tag and [mysqld]

respectively.

Chinese garbled code in php database

Chinese garbled code in php database##

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!

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