DB ERROR:mysqli_num_rows()期望参数1为mysqli_result,给定null

时间:2016-12-05 21:39:52

标签: php mysql mysqli

请将其他问题转介给我,因为我已经尝试过了

我为我的CMS构建的身份验证系统存在问题,首先我有一个专门用于运行查询等的类,这里是。

<?php
defined('LATRINA') or exit('You cannot view this file.');

class Database
{
    private $connection;

    public function connect()
    {
        $config = Latrina::getLibrary('latrina.config.config');

        $this->connection = mysqli_connect(
            $config->getConfig('database', 'hostname'),
            $config->getConfig('database', 'username'),
            $config->getConfig('database', 'password'),
            $config->getConfig('database', 'name'),
            $config->getConfig('database', 'port'));

        if ($this->connection->connect_errno)
        {
            echo 'Failed to connect to MySQL: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error;
        }
    }

    public function query($query)
    {
        if (!$this->connection->query($query)) {
            echo 'Error in MySQL query: ' . $query . '<br>' . $mysqli->error;
        }
    }

    public function rows($query)
    {
        $result = $this->query($query);
        return mysqli_num_rows($result);
    }

    public function getConnection()
    {
        return $this->connection;
    }
}
?>

然后我在这里运行查询......

if (!$this->loggedIn() && Latrina::getLibrary('latrina.database.database')->rows("SELECT `username` FROM `users` WHERE `username` = '" . $attemptUsername . "' AND `password` = '" . $attemptPassword . "'") > 0)
        {
            $_SESSION['user']['username'] = $attemptedUsername;
            $_SESSION['user']['id'] = getId($attemptedUsername);
        }

我收到以下错误信息:

E_WARNING文件 database.class.php 第35行出错:mysqli_num_rows()要求参数1为mysqli_result,给定为null

0 个答案:

没有答案