gpt4 book ai didi

php - 如何检查获取的结果集是否为空?

转载 作者:行者123 更新时间:2023-12-05 03:07:01 26 4
gpt4 key购买 nike

例如:

$sql = 'select a, b, c from table where condition';
$stmt->prepare($sql);
$stmt->execute();
$data = $stmt->fetch();

 $sql = 'select a, b, c from table where condition';
$stmt->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll();

如何判断结果集是否为空

最佳答案

检查 $data 变量,如:

if ($data) {
//not empty
} else {
// empty
}

如果 SELECT 查询的结果返回任何数据,变量 $data 将包含一个非空数组/对象,其计算结果为 true,否则为类似假的值。

关于php - 如何检查获取的结果集是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48538738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com