php mysql PHP MYSQL garbled problem, use SET NAMES utf8 to correct it

WBOY
Release: 2016-07-29 08:41:18
Original
844 people have browsed it

Write it down first, so that you don’t have to remember it and look for it everywhere later!
When PHP operates the database, the data in the database uses UTF8 encoding. When it is read out, all that is displayed is ???????question marks and garbled characters. I found some The data is originally encoded before reading:

Copy code The code is as follows:


create table tablename
(
id int not null auto_increment,
title varchar(20) not null,
contnet varchar (300) defalut null,
primary key ('id')
)begin=MyISAM DEFAULT CHARSET =UTF8;


Execute before inserting data:

Copy code The code is as follows:


mysql_query(" SET NAMES utf8");


Then
mysql_query("insert into tablename....")
Execute before reading out the data:

Copy the code The code is as follows:


mysql_query("SET NAMES utf8");


Then mysql_query("select * from tablename")
Note: The encoding read here is output after re-encoding the original encoding content. For example, if the page where the output content is located is GBK encoding, then in When reading, the page display is also garbled, so execute mysql_query("SET NAMES gbk") before querying, and the GBK-encoded text content can be displayed normally on the page.

The above introduces the php mysql PHP MYSQL garbled problem, using SET NAMES utf8 correction, including the content of php mysql. I hope it will be helpful to friends who are interested in PHP tutorials.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!