“ mysqli_query()期望参数1为mysqli,给定为null”是什么意思?

时间:2019-07-15 20:19:46

标签: php

我是编程的初学者。

为什么在函数displayUsers()中未评估$ this->连接?

这是PHP代码:

class T_MySQLDB{
    public $connection;    //The MySQL database connection

    function mysqldb($connection)
    {$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME) or die(mysqli_connect_error());}

    function displayUsers()
    {   
        $q = "SELECT username,password "
            ."FROM ".TBL_USERS." ORDER BY username";
        $result = mysqli_query($this->connection, $q);

        $num_rows = mysqli_num_rows($result);
        return $num_rows; 
    }
}
    /* Create database connection */
    $tdatabase = new T_MySQLDB;
    echo $tdatabase->displayUsers();

0 个答案:

没有答案