- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
prepare($s-6ren">
$sql = "CALL pr_cartItemsForCustomer (:customerId)";
$statement = $connection->prepare($sql);
$statement->bindValue(':customerId',$customerId);
$statement->execute();
if($statement->columnCount() > 0)
即使没有返回行,它也总是返回 5 列,检查没有行的正确方法是什么?我尝试了 rowCount 但没有成功。
该代码对于查询可以正常工作,但在调用返回查询的存储过程时则不行。
最佳答案
查找返回行数的正确方法是使用 count()
在返回的 PHP 数组上。
$sql = "CALL pr_cartItemsForCustomer (:customerId)";
$statement = $connection->prepare($sql);
$statement->bindValue(':customerId',$customerId);
$statement->execute();
$results = $statement->fetchAll();
echo count($results);
但是,请注意您的示例根本不需要它。如果您只想检查任何返回的行,则只需使用数组本身作为 bool 值。例如if($results)
了解更多信息 https://phpdelusions.net/pdo#count
$results = $statement->fetchAll();
if($results) {
foreach($result as $row) {
// ...
}
} else {
echo 'No records!';
}
关于php - 使用 php pdo 对 mysql 数据库调用存储过程后检查没有行 columnCount 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58466428/
代码:
我有两个模型: MyModel ( inherits QAbstractItemModel ,它的树)和 MyProxyModel (inherits QSortFilterProxyModel)。
QTreeView忽略从QAbstractListModel继承的类的columnCount()并仅显示第一列: import sys from PyQt5.QtCore import QAbstra
我在做什么:尝试使用 onGlobalLayout() 中的 setColumnCount() 更改 GridLayout 的列数 的 OnGlobalLayoutListener() 我想达到什么目
我在很多事情上都使用 datagridview,我认为它是一个非常强大的数据查看器工具。我的问题是,我正在使用这段代码: for (int i = 0; i < dataGridView1.**Col
在 Java 中,我可以说: private double[][] data; 并初始化它: Data = new double[rowCount][columnCount] 但是,在 C# 中,我会
$sql = "CALL pr_cartItemsForCustomer (:customerId)"; $statement = $connection->prepare($s
我正在尝试在 android.support.v7.widget.GridLayout 中使用 columnCount 属性,但出现错误 错误:(2) 在包中找不到属性“useDefaultMargi
正如标题所暗示的那样,我正在尝试从结果数据集中检索表模型。我仍在学习如何使用数据库,所以我目前正在使用以下代码: import java.sql.ResultSet; import java.sql.
试图更多地了解 QAbstractTableModel,我遇到了 rowCount 和 columnCount 的虚拟方法,这些方法在继承 QAbstractTableModel 时需要实现。 拿 i
我是一名优秀的程序员,十分优秀!