【问题标题】:num_rows alternative for webspace without MySQLnd没有 MySQLnd 的网络空间的 num_rows 替代方案
【发布时间】:2017-09-16 19:15:51
【问题描述】:

似乎我托管我的网络服务器的公司没有安装 MySQLnd(或者至少没有安装在我的服务器上)。这意味着在php中我不能使用$stmt->get_result(),这意味着我不能使用$result->num_rows()。我不得不使用$stmt->bind_result()$stmt->fetch()。在我的情况下,是否有替代方法可以轻松获取行数而无需使用fetch() 循环?

另外,$result->num_rows_affected() 也有同样的问题。

【问题讨论】:

  • 我很困惑,为什么不能使用$stmt->get_result(),它不可用? MySQLi 或其他库可用吗?
  • 明白了。如果我记得,有一种方法可以从准备好的语句中获取数字。

标签: php mysqli mysqlnd


【解决方案1】:

似乎没有其他选择。我能做的最好的就是创建一个循环遍历行并返回计数的方法:

function rowCount($stmt) {
    $count = 0;
    while ($stmt->fetch()){
        $count++;
    }
    $stmt->data_seek(0); //reset the stmt to the first row
    return $count;
}

请注意,这并不能解决 rows_affected 问题。

【讨论】:

    猜你喜欢
    • 2020-09-07
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多