偏移量0对MySQL结果索引64无效(或查询数据未缓冲) [英] Offset 0 is invalid for MySQL result index 64 (or the query data is unbuffered)

查看:105
本文介绍了偏移量0对MySQL结果索引64无效(或查询数据未缓冲)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php和mysql,突然间我得到了

I am working with php and mysql and suddenly I get

mysql_data_seek()[function.mysql-data-seek]:偏移0对MySQL结果索引64无效(或查询数据未缓冲)

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

这是什么意思.

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

I have no idea where to start to debug this one.


该类将mysql资源传递到其构造函数中


This class is passed a mysql resource into it's constructor

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()之前没有检查结果集是否为空.

if the result set is empty mysql_data_seek() will fail with a E_WARNING. That is I think happening in you case because you are not checking whether the result set is empty or not before calling the mysql_data_seek().

如果行数大于等于1,则始终检查结果,然后可以安全地呼叫mysql_data_seek()

Always check the result for number of rows if they are >=1 then you are safe to call mysql_data_seek()

这篇关于偏移量0对MySQL结果索引64无效(或查询数据未缓冲)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆