连接成功 致命错误:在第 7 行对非对象调用成员函数 prepare()。为什么会出现此错误?这是论坛的开始。我准备用'if ($query = $db->prepare($sql))。
<?php
session_start();
$db = mysql_connect("localhost","root","","my_db") or die ("Could not connect to database.");
echo 'Connected Successfully';
$sql = "SELECT forum_id, forum_name FROM forum_tbl";
if ($query = $db->prepare($sql)){
$query->bind_result($f_id, $f_name);
$query->execute();
$query->store_result();
}else{
echo $db->error;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Forum</title>
<meta/>
<style type="text/css">
</style>
</head>
<body>
<div class="container">
<div class="content">
<table align="center" width="80%">
<?php
if($query->num_rows !==0):
while($row = $query->fetch()):?>
<tr>
<td><a href="forum.php?id=<?php echo $f_id?>"><?php echo $f_name;?> </a></td>
</tr>
<?php endwhile; endif;?>
</table>
</div>
</div>
</body>
</html>