Call to a member function fetch_row() on a non-object的问题

zonas1991 2012-11-05 10:34:16
运行出错:Fatal error: Call to a member function fetch_row() on a non-object in E:\AppServ\www\exercitation\Show.php on line 30

<?PHP
$existRecord = False;
$objContent = new Content();
$results = $objContent->load_content_byPage($pageNo, $pageSize);
// 使用while语句显示所有$results中的留言数据
while($row = $results->fetch_row()) { //第30行
$existRecord = True;
?>


最后也有如果没数据输出了。
<?PHP
} // end of while
if(!$existRecord) {
?>
<tr>
<td width="148" height="16" align=center class="main">没有留言数据</td>
</tr>
<?PHP
} // end of if
echo("</table></center></div>");
} // end of function
?>

数据库连接是没问题的。数据也有手动插入了。
...全文
972 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
一起混吧 2012-11-06
  • 打赏
  • 举报
回复
echo $sql ;//贴出结果
zonas1991 2012-11-06
  • 打赏
  • 举报
回复
引用 4 楼 jordan102 的回复:
$result = $this->conn->query($sql) or die($this->conn->error); //改成这样能不能看到错误信息
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
一起混吧 2012-11-06
  • 打赏
  • 举报
回复
$result = $this->conn->query($sql) or die($this->conn->error); //改成这样能不能看到错误信息
ayzen1988 2012-11-06
  • 打赏
  • 举报
回复
你这个数据库类是不是少了一个query()函数? 还是你粘贴少了?
function query($sql)
{
 return mysqli_query($this->con,$sql);
}
zonas1991 2012-11-05
  • 打赏
  • 举报
回复
<?PHP class Content { var $conn; public $ContId; // 留言ID号,主键 public $Subject; // 留言标题 public $Words; // 留言内容 public $UserName; // 留言人姓名 public $Face; // 脸谱图标文件名 public $Email; // 电子邮件 public $Homepage; // 主页 public $CreateTime; // 创建日期和时间 public $UpperId; // 上级留言ID,如果不是回帖,则UpperId = 0 function __construct() { // 连接数据库 $this->conn = mysqli_connect("localhost", "root", "110120", "book"); mysqli_query($this->conn, "SET NAMES gbk"); } function __destruct() { // 关闭连接 mysqli_close($this->conn); } // 获取留言的内容 function GetInfo($Id) { $sql = "SELECT * FROM Content WHERE ContId=" . $Id; $result = $this->conn->query($sql); if($row = $result->fetch_row()) { $this->ContId = $Id; $this->Subject = $row[1]; $this->Words = $row[2]; $this->UserName = $row[3]; $this->Face = $row[4]; $this->Email = $row[5]; $this->Homepage = $row[6]; $this->CreateTime = $row[7]; $this->UpperId = (int)$row[8]; } } // 返回表Content中的记录总数量 function GetRecordCount() { $sql = "SELECT COUNT(*) FROM Content"; $result = $this->conn->query($sql); if($row = $result->fetch_row()) Return (int)$row[0]; else Return 0; } // 插入新记录 function insert() { $sql = "INSERT INTO Content (Subject, Words, UserName, Face, Email, Homepage, CreateTime, UpperId) VALUES('" . $this->Subject . "', '" . $this->Words . "', '" . $this->UserName . "', '" . $this->Face . "', '" . $this->Email . "', '" . $this->Homepage . "', '" . $this->CreateTime . "', " . $this->UpperId . ")"; $this->conn->query($sql); } // 删除指定的留言记录 function delete($Id) { $sql = "DELETE FROM Content WHERE ContId=" . $Id . " OR UpperId=" . $Id; $this->conn->query($sql); } function load_content_byUpperid($uid) { $sql = "SELECT * FROM Content WHERE UpperId=" . $uid . " ORDER BY CreateTime DESC"; $result = $this->conn->query($sql); Return $result; } function load_content_byPage($pageNo, $pageSize) { $sql = "SELECT * FROM Content ORDER BY CreateTime DESC LIMIT " . ($pageNo-1) * $pageSize . "," . $pageSize; $result = $this->conn->query($sql); Return $result; } } ?>
zonas1991 2012-11-05
  • 打赏
  • 举报
回复
引用 1 楼 jordan102 的回复:
$results 不是一个资源集,初步怀疑数据库操作类没有传入函数。
不明白,我把数据库操作全贴出来吧
一起混吧 2012-11-05
  • 打赏
  • 举报
回复
$results 不是一个资源集,初步怀疑数据库操作类没有传入函数。
Twitter Digg Facebook Del.icio.us Reddit Stumbleupon Newsvine Technorati Mr. Wong Yahoo! Google Windows Live Send as Email Add to your CodeProject bookmarks Discuss this article 85 Print Article Database » Database » Other databasesLicence CPOL First Posted 19 Jan 2012 Views 24,219 Downloads 992 Bookmarked 74 times RaptorDB - The Key Value Store V2 By Mehdi Gholam | 8 Mar 2012 | Unedited contribution C#.NETDBABeginnerIntermediateAdvanceddatabase Even faster Key/Value store nosql embedded database engine utilizing the new MGIndex data structure with MurMur2 Hashing and WAH Bitmap indexes for duplicates. See Also More like this More by this author Article Browse Code Stats Revisions (8) Alternatives 4.95 (56 votes) 1 2 3 4 5 4.95/5 - 56 votes μ 4.95, σa 1.05 [?] Is your email address OK? You are signed up for our newsletters but your email address is either unconfirmed, or has not been reconfirmed in a long time. Please click here to have a confirmation email sent so we can confirm your email address and start sending you newsletters again. Alternatively, you can update your subscriptions. Add your own alternative version Introduction What is RaptorDB? Features Why another data structure? The problem with a b+tree Requirements of a good index structure The MGIndex Page Splits Interesting side effects of MGIndex The road not taken / the road taken and doubled back! Performance Tests Comparing B+tree and MGIndex Really big data sets! Index parameter tuning Performance Tests - v2.3 Using the Code Differences to v1 Using RaptorDBString and RaptorDBGuid Global parameters RaptorDB interface Non-clean shutdowns Removing Keys Unit tests File Formats File Format : *.mgdat File Format : *.mgbmp File Format : *.mgidx File Format : *.mgbmr , *.mgrec History Download RaptorDB_v2.0.zip - 38.7 KB Download RaptorDB_v2.1.zip - 39 KB Download RaptorDB_v2.2.zip - 39 KB Download RaptorDB_v2.3.zip - 39.6 KB D

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧