Home > Backend Development > PHP Problem > What should I do if the PHP database cannot insert Chinese characters?

What should I do if the PHP database cannot insert Chinese characters?

藏色散人
Release: 2023-03-11 07:48:01
Original
2346 people have browsed it

Solution to the problem that Chinese cannot be inserted into the php database: 1. Add "" to PHP; 2. Open the data and add " mysql_query("set names utf-8");".

What should I do if the PHP database cannot insert Chinese characters?

##The operating environment of this article: linux5.9.8 system, PHP7.1 version, Dell G3 computer

What should I do if the php database cannot insert Chinese characters?

php mysql cannot insert Chinese characters

Write PHP today to operate the MySQL database The program displays a question mark when inserting Chinese characters, as shown below:

| abcdef3233 | 123456  | abcdef3233@163.com   | ????????? | 2011-12-25 10:22:47 |
Copy after login

When directly operating the database under Linux, the display is normal. Later it was found that the page encoding and database encoding were inconsistent. Solution:

Add to the PHP program:

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Copy after login

After opening the data, add:

 mysql_query("set names utf-8");
Copy after login

Of course, I use utf-8 encoding here. If you are using gb2312 Encoding, utf-8 needs to be changed accordingly.

Problem solved.

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What should I do if the PHP database cannot insert Chinese characters?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template