运行出错: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
?>数据库连接是没问题的。数据也有手动插入了。
$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
?>数据库连接是没问题的。数据也有手动插入了。
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;
}
}
?>
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
还是你粘贴少了?
function query($sql)
{
return mysqli_query($this->con,$sql);
}