gpt4 book ai didi

php - 如果结果集为空,MySQL 和 pdo::fetchColumn() 返回什么?

转载 作者:行者123 更新时间:2023-11-29 06:26:06 24 4
gpt4 key购买 nike

$sql='SELECT id FROM mytable WHERE x=?';
$stmt=$conn->prepare($sql);
$stmt->execute(array(123));
$id=$stmt->fetchColumn();
syslog(LOG_INFO,'id ='.$id.' and is '(is_null($id)?'null':'not null'));

PHP $stmt->fetchColumn() 返回看似为 null 的内容,但在测试时并非如此。

MySQL 在 shell 上测试时表明 MySQL 返回了一个空结果集(即零行)。 (查询耗时 0.0008 秒)

什么是 $stmt->fetchColumn() 返回空结果集?

最佳答案

来自 PHP documentation :

Returns a single column from the next row of a result set or FALSE if there are no more rows.

对于获取,使用:

单行获取:

$stmt->fetch();

多行获取:

while($stmt->fetch()) { 
//do something
}

关于php - 如果结果集为空,MySQL 和 pdo::fetchColumn() 返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30893547/

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