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.
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);
}
}
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With