PHP uses the Mysqli module to connect the database fatal Error:call to a member function query () ....
This error has occurred: Fatal Error:call to a member function query () on a non-object in D:\wamp\www\bills\model\UserDB.class.php on line 24
The code is as follows:
PHP Code
Mysqli=new mysqli ($dbhost, $dbuser, $dbpwd, $dbname); if (Mysqli_connect_errno ()) {echo "Item database connection failed! "; }} public function close () {if ($this->mysqli) $this->mysqli->clo SE (); $this->mysqli=false; Public Function _destruct () {$this->close (); }} class UserDB extends Database {public Function queryuserbyname ($name) {$query = "SEL ECT * from Users WHERE name= ' ". $name." ' "; if ($result = $this->mysqli->query ($query))//Prompt error here!! return true; else return false; }
Then invoke the above class object in another page:
PHP Code
Queryuserbyname ($lvalue ["name"]); echo "alert"; if ($rtmp)//This name is not registered {$rusers =new User ($lvalue); if ($udb->adduser ($rusers)) {Setcookie ("start", 0); Setcookie ("UserInfo", Serialize ($rusers)); Setcookie ("username", $rusers->name); Header ("Location:.. /view/index.php "); } else Header ("Location:.. /view/errors.php?value=tianjia "); } break; }
------Solution--------------------
Public function __construct ($configFile = "config.inc.php")//Two underline