刚学PHP,在函数调用时出现
Fatal error: Call to a member function db_fetch_array() on a non-object in D:\masterphp\mybbs\index.php on line 18(即是:while($row=$db->db_fetch_array($result)){ 这行)我是新手,面对这问题弄了好久也没解决,下面是相关的代码
--------------------------------------------------------------------------------------------------------------
<?php
require("conn.php");
?>
<table width="90%" border="1" bordercolor="#000000" align="center" cellpadding="5" cellspacing="0">
<tr bgcolor="#B10707">
<td colspan="3" style="color:#FFF"><strong>论坛列表</strong></td>
</tr>
<tr bgcolor="#FDF7AF">
<td width="6%">状态</td>
<td width="70%">论坛</td>
<td width="24%">最后更新</td>
</tr>
<?php
$sql="select * from forums";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0){
while($row=$db->db_fetch_array($result)){
?>
<tr>
<td></td>
<td><?php echo "<div class=\"bold\"><a class=\"forum\" href=\"forums.php?F=".$row["ID"]."\">".$row["forum_name"]."</a></div>".$row["forum_description"] ?></td>
<td><div><?php echo $row["last_post_time"]." By ".$row["last_post_author"]?></div></td>
</tr>
<?php
}
}else{
echo "<tr><td colspan=3>对不起,论坛尚在建设中……</td></tr>";
}
close_db();
?>
</table>
Fatal error: Call to a member function db_fetch_array() on a non-object in D:\masterphp\mybbs\index.php on line 18(即是:while($row=$db->db_fetch_array($result)){ 这行)我是新手,面对这问题弄了好久也没解决,下面是相关的代码
--------------------------------------------------------------------------------------------------------------
<?php
require("conn.php");
?>
<table width="90%" border="1" bordercolor="#000000" align="center" cellpadding="5" cellspacing="0">
<tr bgcolor="#B10707">
<td colspan="3" style="color:#FFF"><strong>论坛列表</strong></td>
</tr>
<tr bgcolor="#FDF7AF">
<td width="6%">状态</td>
<td width="70%">论坛</td>
<td width="24%">最后更新</td>
</tr>
<?php
$sql="select * from forums";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0){
while($row=$db->db_fetch_array($result)){
?>
<tr>
<td></td>
<td><?php echo "<div class=\"bold\"><a class=\"forum\" href=\"forums.php?F=".$row["ID"]."\">".$row["forum_name"]."</a></div>".$row["forum_description"] ?></td>
<td><div><?php echo $row["last_post_time"]." By ".$row["last_post_author"]?></div></td>
</tr>
<?php
}
}else{
echo "<tr><td colspan=3>对不起,论坛尚在建设中……</td></tr>";
}
close_db();
?>
</table>
----------------------------------------------<?php
mysql_connect("localhost","root","123456");
mysql_select_db("mybbs");
/*或者你可以这样写:
$connect_db=mysql_connect("localhost","root","root");
mysql_select_db("mybbs",$connect_db);
*/ Function close_db(){
mysql_close();
}
//注意:函数一种是带返回值的,一种没有值。
?>