php获取mysql汉语言后显示乱码,能帮修改一下吗
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php获取mysql汉语言后显示乱码,能帮修改一下吗,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2158字,纯文字阅读大概需要4分钟。
内容图文
![php获取mysql汉语言后显示乱码,能帮修改一下吗](/upload/InfoBanner/zyjiaocheng/222/762368e7e360466e97069177fd91515d.jpg)
<?php
header("Content-type: text/html; charset=utf-8");
$dsn = 'mysql:host=localhost;dbname=pw9';
$db = new PDO($dsn,'root','');
$rs = $db->query('SELECT * FROM pw_bbs_threads');
while($row=$rs->fetch()){
print_r($row);
}
1.文件编码utf8
2.mysql编码utf8
3.浏览器编码utf8
搜索了很多,发现有人说要set names utf8,可是在我这个代码里面不知道如何写,麻烦高人修改一下谢谢 分享到:
------解决方案--------------------
$db->query("SET NAMES utf8");
------解决方案--------------------
这样写比较好
$db = new PDO($dsn,'root','', array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
不会忘了写 $db->query("SET NAMES utf8"); 而出问题
------解决方案--------------------
手册上不是有吗?
预定义常量
以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。
PDO_PARAM_BOOL (integer)
Represents a boolean data type.
PDO_PARAM_NULL (integer)
Represents the SQL NULL data type.
PDO_PARAM_INT (integer)
Represents the SQL INTEGER data type.
PDO_PARAM_STR (integer)
Represents the SQL CHAR, VARCHAR, or other string data type.
PDO_PARAM_LOB (integer)
Represents the SQL large object data type.
PDO_PARAM_STMT (integer)
PDO_PARAM_INPUT_OUTPUT (integer)
Specifies that the parameter is an INOUT parameter for a stored procedure. You must bitwise-OR this value with an explicit PDO_PARAM_* data type.
PDO_FETCH_LAZY (integer)
Specifies that the fetch method shall return each row as an object with variable names that correspond to the column names returned in the result set. PDO_FETCH_LAZY creates the object variable names as they are accessed.
PDO_FETCH_ASSOC (integer)
Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. If the result set contains multiple columns with the same name, PDO_FETCH_ASSOC returns only a single value per column name.
PDO_FETCH_NAMED (integer)
Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. If the result set contains multiple columns with the same name, PDO_FETCH_NAMED returns an array of values per column name.
内容总结
以上是互联网集市为您收集整理的php获取mysql汉语言后显示乱码,能帮修改一下吗全部内容,希望文章能够帮你解决php获取mysql汉语言后显示乱码,能帮修改一下吗所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。