首页 > 后端开发 > php教程 > 请问使用php的pdo查询出来怎么会是空白?

请问使用php的pdo查询出来怎么会是空白?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-23 14:23:01
原创
1008 人浏览过

我有一个php是这样写的:

<?phprequire('inc/pdo.php');$lt=$dbc->prepare(" select b.subject from pre_forum_forum a inner join pre_forum_forum aa on a.fid=aa.fup inner join pre_forum_thread b on b.fid=aa.fid where a.name='你好'");$lt->execute();while($row=$lt->fetch()){print_r($row);};?>
登录后复制


打开页面是一片空白,本以为是写错了,就换了一个sql语句:
select * from tablename


这样就正常,请教大神这是为什么?


回复讨论(解决方案)

这个sql语句已经跑过,没有错!

求大神啊。。。。

from pre_forum_forum a
可以直接from a


a.name='你好'
有字符集问题。

如果pdo 对应的mysql 版本不对,会有这个bug

如果pdo 对应的mysql 版本不对,会有这个bug
我这个是对的啊

$arr = $lt->errorInfo();
print_r($arr); //这样看看

$arr = $lt->errorInfo();
print_r($arr); //这样看看

<?phprequire('inc/pdo.php');//$wlt='你好';$lt=$dbc->prepare("select b.subject from pre_forum_forum a inner join pre_forum_forum aa on a.fid=aa.fup inner join pre_forum_thread b on b.fid=aa.fid where a.name='你好'");//$lt->execute(array($wlt));//while($row=$lt->fetch()){//print_r($row);//};$arr = $lt->errorInfo();print_r($arr); ?>
登录后复制


结果是:
Array ( [0] => [1] => [2] => )

把上面的注释全部删掉再试

把上面的注释全部删掉再试

<?phprequire('inc/pdo.php');$wlt='你好';$lt=$dbc->prepare("select b.subject from pre_forum_forum a inner join pre_forum_forum aa on a.fid=aa.fup inner join pre_forum_thread b on b.fid=aa.fid where a.name=?");$lt->execute(array($wlt));while($row=$lt->fetch()){print_r($row);};$arr = $lt->errorInfo();print_r($arr); ?>
登录后复制


结果还是:Array ( [0] => 00000 [1] => [2] => )

Array ( [0] => 00000 [1] => [2] => )
表示没有语法错,但不表示一定有结果
你的查询条件是中文的,那么就有一个字符集问题
字符集不对,就查不到了

另外就常理而言
a.name='你好'
你不觉得有点怪异吗?

可能是字符集问题,在prepare前面加上
$dbc->query('set names utf8');   

Array ( [0] => 00000 [1] => [2] => )
表示没有语法错,但不表示一定有结果
你的查询条件是中文的,那么就有一个字符集问题
字符集不对,就查不到了

另外就常理而言
a.name='你好'
你不觉得有点怪异吗?
这个只是数据库起的别名, 问题解决了                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

我就说有字符集问题。你不听

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
JS跳转到PHP页面卡住
来自于 1970-01-01 08:00:00
0
0
0
php 实例ajax与mysql怎么只查询出一条数据?
来自于 1970-01-01 08:00:00
0
0
0
添加 cookie 标头会导致请求挂起
来自于 1970-01-01 08:00:00
0
0
0
Node.js中,Inquirer在我做出选择之前退出
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板