php

This question already has an answer here:

  • mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource 31 answers

  • 当你需要传递$result作为你的db结果对象时,你正在传递$query ,这是你的sql字符串

    class DBQueries extends DBConn {
        function displayUsers(){
            $this->dbConnection();
            $query = "SELECT * FROM users";
            $result = mysql_query($query);
            while ($row = mysql_fetch_array($result)) {
                echo $row['password'];
            }
        }
    }
    

    你需要传递mysql_query()返回的结果句柄$result


    您需要将$ result作为第一个参数传递给mysql_fetch_array函数调用,而不是$ query。

    class DBQueries extends DBConn {
      function displayUsers(){
        $this->dbConnection();
        $query = "SELECT * FROM users";
        $result = mysql_query($query);
        while ($row = mysql_fetch_array($result)) {
          echo $row['password'];
        }
      }
    }
    
    链接地址: http://www.djcxy.com/p/69594.html

    上一篇: 查询MySQL连接2个数据库

    下一篇: PHP