Home > Backend Development > PHP Problem > Chinese garbled code in php database

Chinese garbled code in php database

Release: 2023-02-27 20:52:02
Original
3024 people have browsed it

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

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

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!

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