簡體   English   中英

偏移0對於MySQL結果索引64無效(或查詢數據未緩沖)

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

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

mysql_data_seek()[function.mysql-data-seek]:偏移0對MySQL結果索引64無效(或查詢數據未緩沖)

這是什么意思。

我不知道從哪里開始調試這個。


這個類將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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM