【问题标题】:how to replace get_result() function properly如何正确替换 get_result() 函数
【发布时间】:2016-02-17 14:00:09
【问题描述】:

is this mean mysqlnd is working on the server?

我在我的php文件中使用了这样的函数,但是主机没有mysqlnd。

那么如何正确替换get_result()函数呢?

我看到了一个解决方案,但未能实施,所以请举个例子。谢谢!

public function getFromDb($tableName) {
    $stmt = $this->conn->prepare("SELECT * FROM ".$tableName);
    $stmt->execute();
    $result= $stmt->get_result();
    $stmt->close();
    return $result;
}

【问题讨论】:

  • 换成什么?
  • 语法和格式
  • 任何选择@DerVO

标签: php mysqlnd


【解决方案1】:

MySQLi prepare() 返回 mysqli_stmt 对象,但要使用 fetch* 函数,您需要一个 mysqli_result 对象。因此,您的函数应该如下所示:

public function getFromDb($tableName) {
    $result = $this->conn->query("SELECT * FROM ".$tableName);
    if (empty($result)) {
        return FALSE;
    }
    return $result->fetch_assoc();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2018-11-22
    • 2012-05-31
    • 2011-10-12
    相关资源
    最近更新 更多