Home > Backend Development > PHP Tutorial > 再度遭遇PHP对MYSQL插入中文和显示时出现乱码

再度遭遇PHP对MYSQL插入中文和显示时出现乱码

WBOY
Release: 2016-06-13 13:24:26
Original
1058 people have browsed it

再次遭遇PHP对MYSQL插入中文和显示时出现乱码
之前搞定了这些程序,今天删除数据库后再整理一下程序,对数据库插入中文,又开始出现乱码了。

1,我的

页面,在HTML内容里定义页面编码:

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

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


2,在mysql建立数据库和表时,定义编码:
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$sqlb =    "create table test     
    (
        .....
    )
    ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;"; 

[b]3,连接数据库时,定义编码:[/b]
[code=PHP]
$conn=mysql_connect($host,$user,$pwd);
mysql_query("SET
       character_set_connection=utf-8,
       character_set_results=utf-8,
       character_set_client=binary",$conn);

Copy after login


...
以上已经保证了数据库,页面,甚至数据库连接全部都是统一编码:UTF-8格式。

可是为啥对数据库中插入中文时,还是显示乱码呢?

------解决方案--------------------
PHP code
$conn=mysql_connect($host,$user,$pwd);
mysql_query("SET
       character_set_connection=utf-8,//这里的utf-8改写成utf8
       character_set_results=utf-8,//同上
       character_set_client=binary",$conn);
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

引用:

PHP code
$conn=mysql_connect($host,$user,$pwd);
mysql_query("SET
character_set_connection=utf-8,//这里的utf-8改写成utf8
character_set_results=utf-8,//同上
character_set_client=binary",$………
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