Rumah > pembangunan bahagian belakang > tutorial php > 请问使用php的pdo查询出来怎么会是空白?

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

WBOY
Lepaskan: 2016-06-23 14:23:01
asal
984 orang telah melayarinya

我有一个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);};?>
Salin selepas log masuk


打开页面是一片空白,本以为是写错了,就换了一个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); ?>
Salin selepas log masuk


结果是:
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); ?>
Salin selepas log masuk


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

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

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan