我正在使用 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/