如果 num_rows = 0 在 php 中从 mysqli 准备好的语句中显示消息

发布于 2024-10-28 04:07:11 字数 292 浏览 2 评论 0原文

我在尝试从 php 中的准备好的语句查询中获取行数时遇到问题,我的查询如下所示:

$DBH = getDBH();
$stmt = $DBH->prepare("SELECT info FROM list WHERE tag = ?");
$stmt->bind_param("s",$tag);
$stmt->execute();
$stmt->bind_result($information);

我基本上只是想说,如果没有返回结果,则显示“没有返回结果”,有人可以帮忙吗?

I am having an issue trying to get the number of rows from a prepared statement query in php, my query looks as follows:

$DBH = getDBH();
$stmt = $DBH->prepare("SELECT info FROM list WHERE tag = ?");
$stmt->bind_param("s",$tag);
$stmt->execute();
$stmt->bind_result($information);

and i basically just want to say if there is no result returned display "no result returned" can anyone please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安稳善良 2024-11-04 04:07:12

我不认识你正在使用的类,但通常我会这样做:

$sql = "SELECT * FROM dummy WHERE category=13";
$result = mysql_query($sql);
if(mysql_num_rows($result)>0) {
// execute for positive results
} else {
// execute for 0 rows returned.
}

I don't recognize the class you are using, but generally I do this:

$sql = "SELECT * FROM dummy WHERE category=13";
$result = mysql_query($sql);
if(mysql_num_rows($result)>0) {
// execute for positive results
} else {
// execute for 0 rows returned.
}
魔法少女 2024-11-04 04:07:12
$sql = "SELECT * FROM dummy WHERE category=13";
$result = mysqli_query($link, $sql);
$numrows=mysqli_num_rows($result)
if($numrows>0) {
// execute for positive results
} else {
// execute for 0 rows returned.
}
$sql = "SELECT * FROM dummy WHERE category=13";
$result = mysqli_query($link, $sql);
$numrows=mysqli_num_rows($result)
if($numrows>0) {
// execute for positive results
} else {
// execute for 0 rows returned.
}
清泪尽 2024-11-04 04:07:11

您需要首先使用$statement->store_result()。使用您的代码:

$DBH = getDBH();
$stmt = $DBH->prepare("SELECT info FROM list WHERE tag = ?");
$stmt->bind_param("s",$tag);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
$stmt->bind_result($information);

You need to use $statement->store_result() first. Using your code:

$DBH = getDBH();
$stmt = $DBH->prepare("SELECT info FROM list WHERE tag = ?");
$stmt->bind_param("s",$tag);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
$stmt->bind_result($information);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文