且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查空结果(php,pdo,mysql)

更新时间:2023-02-26 10:32:28

执行$sth->fetchColumn()时,您将丢弃结果行.那不是您检查是否有任何结果的方法.你做

You're throwing away a result row when you do $sth->fetchColumn(). That's not how you check if there's any results. you do

if ($sth->rowCount() > 0) {
  ... got results ...
} else {
   echo 'nothing';
}

此处的相关文档: http://php.net/manual/en/pdostatement.rowcount.php