php - 偏移量 0 对 MySQL 结果索引 64 无效(或者查询数据是无缓冲的)

标签 php mysql

我正在使用 php 和 mysql,突然间我明白了

mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 64 (or the query data is unbuffered)

这是什么意思。

我不知道从哪里开始调试这个。


该类将 mysql 资源传递给它的构造函数

class dbResult {

    private $result;
    private $num_rows;

    function __construct($result) {
        $this->result = $result;
    }

    function result($type = 'object') {
        @mysql_data_seek($this->result, 0);
        if ($type == 'array')
            return mysql_fetch_assoc($this->result);
        if ($type == 'object') {
            if ($this->num_rows() == 1) {
                $data = new stdClass();
                foreach (mysql_fetch_assoc($this->result) as $k => $v)
                    $data->$k = $v;
                return $data;
            }
            if ($this->num_rows() > 1) {
                $data = array();
                while ($result = mysql_fetch_assoc($this->result)) {
                    $row = new stdClass();
                    foreach ($result as $k => $v)
                        $row->$k = $v;
                    $data[] = $row;
                }
                return $data;
            }
            return false;
        }
    }

    function num_rows() {
        return mysql_num_rows($this->result);
    }

    function num_fields() {
        return mysql_num_fields($this->result);
    }

}

最佳答案

如果结果集为空,mysql_data_seek() 将失败并返回 E_WARNING。我认为在您的情况下会发生这种情况,因为您在调用 mysql_data_seek() 之前没有检查结果集是否为空。

总是检查行数的结果,如果它们 >=1 那么你可以安全地调用 mysql_data_seek()

关于php - 偏移量 0 对 MySQL 结果索引 64 无效(或者查询数据是无缓冲的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4860152/

相关文章:

用于 Google Analytics 的 PHP API

php - 如何让zend在sql中设置time_zone

php - MySQL 查询错误,在 PHP 中抛出但在终端中正常。任何解释?

MySQL 更改电子邮件域

php - 遍历json数组并插入mysql php

php - 如何在不使用 PHP 循环的情况下返回 MySQL 结果数组

php - Websocket 并发症

javascript - 我正在尝试使用 jquery 和 ajax 将多个数据发送到另一个页面以检查数据库中是否存在值

php - 教义 findOneBy 方法不起作用

mysql - 多次更新mysql