PHP警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值

时间:2017-03-28 14:58:46

标签: php mysqli boolean

PHP警告: mysqli_fetch_assoc()要求参数1为mysqli_result,第27行/home/rute/dbcontroller.php中给出布尔值

这个错误我不知道怎么修好......我在这里尝试不同的方法,但没有成功......你能帮我解决这个问题吗?

这里是代码:

在index.php中:

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/scripts/dbcontroller.php');
$db_handle = new DBController();

$sql = "SELECT * FROM PRODUCTS WHERE active != '0'";
$posts = $db_handle->runSelectQuery($sql);
?>

这里第27行的dbcontroller.php //是PHP警告

<?php

require($_SERVER['DOCUMENT_ROOT'] . '/scripts/config.php');

class DBController {
    private $conn = "";
    private $host = DB_HOST;
    private $user = DB_USER;
    private $password = DB_PASS;
    private $database = DB_NAME;


    function __construct() {
        $conn = $this->connectDB();
        if(!empty($conn)) {
            $this->conn = $conn;            
        }
    }

    function connectDB() {
        $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
        return $conn;
    }

    function runSelectQuery($query) {
        $result = mysqli_query($this->conn,$query);
        while($row=mysqli_fetch_assoc($result)) {  // HERE IS THE ERROR
            $resultset[] = $row;
        }
        if(!empty($resultset))
            return $resultset;
    }

    function executeInsert($query) {
        $result = mysqli_query($this->conn,$query);
        $insert_id = mysqli_insert_id($this->conn);
        return $insert_id;

    }
    function executeUpdate($query) {
        $result = mysqli_query($this->conn,$query);
        return $result;

    }

    function executeQuery($sql) {
        $result = mysqli_query($this->conn,$sql);
        return $result;

    }

    function numRows($query) {
        $result  = mysqli_query($this->conn,$query);
        $rowcount = mysqli_num_rows($result);
        return $rowcount;
    }
}
?>

0 个答案:

没有答案