简体   繁体   English

偏移0对于MySQL结果索引64无效(或查询数据未缓冲)

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

I am working with php and mysql and suddenly I get 我正在使用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_data_seek()[function.mysql-data-seek]:偏移0对MySQL结果索引64无效(或查询数据未缓冲)

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 这个类将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); } } 

if the result set is empty mysql_data_seek() will fail with a E_WARNING . 如果结果集为空,则mysql_data_seek()将因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() . 这就是我认为在你的情况下发生,因为在调用mysql_data_seek()之前你没有检查结果集是否为空。

Always check the result for number of rows if they are >=1 then you are safe to call mysql_data_seek() 总是检查结果的行数是否> = 1然后你可以安全地调用mysql_data_seek()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM