php - PHP 中的 Mysql 空查询 - 我得到了什么?资源编号?

标签 php mysql resources

我想检查我的查询是否为空(没有行)。最好的应对方式是什么?

我在下面的“$result”和“$row”中得到了什么(这就是我的目标是解决这个问题 - if($result) 或者可能使用 if ($row)表示不为空,有什么更好的建议吗?

谢谢。

       $result = mysql_query("SELECT * FROM table1 WHERE column1= '$var1'
                              AND column2 IN ('no','nein','nope')
                              AND timestamp BETWEEN '$date' AND NOW()"); 
       $row = mysql_fetch_assoc($result);    

最佳答案

测试这个。

$result = mysql_query("SELECT * FROM table1 WHERE column1= '$var1'
                          AND column2 IN ('no','nein','nope')
                          AND timestamp BETWEEN '$date' AND NOW()"); 
$row = mysql_fetch_array($result);

if (mysql_num_rows($result) > 0) {
   echo $row['column name'];
}

关于php - PHP 中的 Mysql 空查询 - 我得到了什么?资源编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9508823/

相关文章:

python - Ant 模拟: it's better to create a Process/Thread for each Ant or something else?

php - 将返回一个表的sql查询,并计算与第一个结果相关的其他表

php - 忽略 preg_replace 中的 img 标签

mysql - 从mysql数据库查询密码哈希返回十进制数的缓冲区数组而不是字符串

php - Mysql 从服务器占用 63 GB

c# - 在 C# 中循环遍历不同语言/文化的嵌入式资源

php - 如何在PHP中使用换行符发送电子邮件

php - 我的 PDO 结构出错 - Php

mysql - 如何将 Anorm RowParser[A] 转换为 RowParser[Option[A]]

wpf - Visual Studio 无法解析 WPF 窗口中的静态资源,即使它在运行时工作 - 为什么?