vendredi 26 juin 2015

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\inhertance\base.php on line 10 [duplicate]

This question already has an answer here:

Message Error..

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\inhertance\base.php on line 10

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\inhertance\base.php on line 11

Notice: Undefined variable: data in C:\xampp\htdocs\inhertance\base.php on line 16

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\inhertance\index.php on line 11



my code

//this page class name is base 
class base {

    //get all user..
    function get($link, $tableName) {

        $query = "SELECT * FROM $tableName";
        $result = mysqli_query($link, $query);
        $num_rows = mysqli_num_rows($result);

        for ($i = 0; $i < $num_rows; $i++) {
            $data[] = mysqli_fetch_assoc($result);
        }
        return $data;
    }

}


//this name page class is users  

require_once './base.php';

class users extends base {

    public $link;

    public function __construct() {
        $this->link;
        $this->tableName = "users";
    }

    function all_user() {
        $data = $this->get($this->link, $this->tableName);
        return $data;
    }

}


//this is page name is index 

require_once './users.php';

require_once './config.php';

$usersObject = new users($link);

$data = $usersObject->all_user();
foreach ($data as $value) {
    echo $value['username'] . "<br />";
}




Aucun commentaire:

Enregistrer un commentaire