Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offset 0 is invalid for MySQL result index 64 (or the query data is unbuffered)

Tags:

php

mysql

I am working with php and mysql and suddenly I get

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

What does this mean.

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


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);
    }

}
like image 251
Hailwood Avatar asked Feb 01 '11 07:02

Hailwood


1 Answers

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().

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

like image 53
Shakti Singh Avatar answered Nov 07 '22 23:11

Shakti Singh