【问题标题】:Extended mysqli_result throwing errors on INSERT type of queries扩展 mysqli_result 在 INSERT 类型的查询上抛出错误
【发布时间】:2011-10-12 18:50:24
【问题描述】:

我像这样扩展了 mysqli_result 类:

class mysqli_Extended extends mysqli {
public function Execute($query) {
    $this->real_query($query);
    return new mysqliResult_Extended($this);
}

public function Insert_Id() {
    return $this->insert_id;
}

public function Affected_Rows() {
    return $this->affected_rows;
}
}

class mysqliResult_Extended extends MySQLi_Result {
public $fields;
public $queryResults;
public $row_count;
public function __construct($opt) {
    parent::__construct($opt);
    $this->queryResults = $this->fetch_all(MYSQLI_BOTH); <-- this is line 28
    $this->fields = $this->queryResults[0];
    $this->row_count = $this->num_rows; <-- this is line 30
    $this->close(); <-- this is line 31
}

public function getrows() {
    return $this->queryResults;
}

public function recordcount() {
    return $this->row_count;
}
}

每次我执行使用 INSERT 的查询时,都会收到以下错误:

Warning: mysqli_result::fetch_all() [mysqli-result.fetch-all]: Couldn't fetch mysqliResult_Extended in /home/xxx/xxx/xxx/xxx/dB.class.php on line 28

Warning: mysqliResult_Extended::__construct() [mysqliresult-extended.--construct]: Couldn't fetch mysqliResult_Extended in /home/xxx/xxx/xxx/xxx/dB.class.php on line 30

Warning: mysqli_result::close() [mysqli-result.close]: Couldn't fetch mysqliResult_Extended in /home/xxx/xxx/xxx/xxx/dB.class.php on line 31

如果我执行 SELECT 类型的查询,则没有错误。

有什么可能导致这种情况的想法吗?

【问题讨论】:

  • 我认为MySQLi_Result不能扩展,必须从mysqli::query()返回。
  • 这段代码用于在我家的服务器上工作,但现在我将它迁移到我的在线服务器,它抛出了这个错误。
  • 两台服务器的 PHP 和 MySQL 版本是多少?
  • 使用mysqlnd编译的在线服务器上的php是5.3.6,mysql是5.0.92
  • 试试看配置有没有区别。

标签: php mysqli


【解决方案1】:

“我收到以下错误:”

这些不是错误 - 它们是警告。

试试var_dump($this-&gt;queryResults);,看看你会得到什么。

我的猜测是,在一个服务器上警告被抑制,而在另一个服务器上却没有。

如果您想抑制警告,您可以在函数调用前使用“@”字符,或适当设置错误级别,如 this question 所示。

【讨论】:

    猜你喜欢
    • 2017-03-03
    • 2017-06-01
    • 2019-09-21
    • 2020-09-27
    • 2015-07-17
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    相关资源
    最近更新 更多