如何在 PHP 中使用 PDO 检查我的结果集是否为空?
$SQL = "SELECT ......... ORDER BY lightboxName ASC;";
$STH = $DBH->prepare($SQL);
$STH->bindParam(':member_id', $member_id);
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row = $STH->fetch()) {
$lightbox_name = $row['lightboxName'];
$lightbox_id = $row['lightboxID'];
echo '<option value="'.$lightbox_id.'">'.$lightbox_name.'</option>';
}
我曾经这样做过:
$result = mysql_query("SELECT ...... ORDER BY lightboxName ASC;");
if(!$result) { echo 'No results found!'; }
但是刚刚开始使用 PDO 并且准备好的语句和检查$STH
似乎没有按预期工作——它总是有价值的!