Home > php教程 > php手册 > php中mysql_query(“set names utf-8″)乱码

php中mysql_query(“set names utf-8″)乱码

WBOY
Release: 2016-05-26 08:21:42
Original
1988 people have browsed it

    我们知道在mysql查询数据库时如果我们中在查询前设置mysql_query是会出现乱码的,但是很多朋友这样设置mysql_query("set names utf-8")但还是乱码这是什么原因呢,下面我们来看看具体设置方法.

是在mysql中用utf8表示utf-8而已,就是指代一种编码.

在php中mysql_query("set names utf-8");因为mysql中定义的是utf8而不是utf-8,所以这条语句是执行不成功的,效果和mysql_query("set names test")一样,所以你存储和获得的mysql编码并没有改变,改为如下代码:

mysql_query("set names utf8");
Copy after login

注意了前面是uft-8而后面是uft8这是有区别的,但这个对于gbk或gbk2312和网页设置又可以一样,这里估计是mysql有原因吧.


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template