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

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

WBOY
WBOY原创
2016-06-23 14:23:01978浏览

我有一个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='你好'
你不觉得有点怪异吗?
这个只是数据库起的别名, 问题解决了                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn