且构网

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

检查空结果(PHP、PDO 和 MySQL)

更新时间:2023-02-26 10:24:08

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

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

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

相关文档在这里:PDOStatement::rowCount

Relevant documentation is here: PDOStatement::rowCount