php 无法使用 empty() 返回 FATAL ERROR 检查 PDO 结果是否为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10677438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php cannot check if a PDO result is empty using empty() returns FATAL ERROR
提问by Brook Julias
I want to check whether my prepared query has returned empty or not without having to go into a loop. This is the code I have tried using:
我想检查我准备好的查询是否返回空,而不必进入循环。这是我尝试使用的代码:
if(empty($pQuery1->fetch(PDO::FETCH_ASSOC))){}
When I try this I get the error:
当我尝试这个时,我收到错误:
Fatal error: Can't use method return value in write context
Fatal error: Can't use method return value in write context
Whether I use PDO->fetchALLor PDO->fetchI receive the same error. Should I be doing something differently?
无论我使用PDO->fetchALL还是PDO->fetch收到相同的错误。我应该做些不同的事情吗?

