Home > Backend Development > PHP Problem > php mysql Chinese garbled code

php mysql Chinese garbled code

angryTom
Release: 2023-02-27 07:32:01
Original
3075 people have browsed it

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

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

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

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

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

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!

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