You can't create an instance of the same class within itself that you are defining. In this case, you're referencing the class DB within the function connect() which is inside the DB class.
Why don't you try creating the instance after the class and defining the variables as constructors?
PHP Code:
<?php
class DB{
private $link;
public static function connect($host,$user,$passwd,$dbname) {
$this->link = new mysqli($host,$user,$passwd,$dbname);
return $this->link;
}
public function query($sql) {
return $this->link->query($sql);
}
}
$db = new DB();
$db->connect("", "", "", "");
?>
Bookmarks