致命错误:在第30行资源上调用成员函数mysql_query()


Fatal error: Call to a member function mysql_query() on resource in line 30

似乎我对这个问题更恼火,我不知道为什么会发生这种情况。非常感谢任何帮助。下面是我的代码:

  <?php include('header.php'); ?>
  <body>
     <table cellpadding="0" cellspacing="0" border="0" class="table" id="">
                    <thead>
                          <tr>
                              <th>Date</th>
                              <th>User</th>
                              <th>Action</th>
                              </tr>                                         
                    </thead>
                    <tbody>
              <?php
                     $query = $link->mysql_query("select * from  activity_log ORDER BY activity_log_id DESC")or die(mysql_error());
                  while($row = $query->fetch()){
                ?>
                                <tr>
                                       <td><?php  echo $row['date']; ?></td>
                                       <td><?php echo $row['username']; ?></td>
                                       <td><?php echo $row['action']; ?></td> 
                                </tr>
                        <?php } ?>

就用

$query = mysql_query("select * from  activity_log ORDER BY activity_log_id DESC");
if (!$query) {
    die('Invalid query: ' . mysql_error());
}

then in while loop

while($row = mysql_fetch_assoc($query))

阅读mysql_query手册和mysql_fetch_assoc手册

注意
此扩展在PHP 5.5.0中已弃用,并将在将来被删除。相反,应该使用MySQLi或PDO_MySQL扩展名。更多信息请参见MySQL:选择API指南和相关FAQ。此函数的替代函数包括:

  1. mysqli_query ()
  2. PDO: query ()

使用

$query = mysql_query("select * from  activity_log ORDER BY activity_log_id DESC")or die(mysql_error());
while($row = mysql_fetch_assoc($query)){
不是

$query = $link->mysql_query("select * from  activity_log ORDER BY activity_log_id DESC")or die(mysql_error());
while($row = $query->fetch()){