Mysqli a bit of a problem, let's see.
I wrote a sqlhelper.class.php tool class, he is mainly instantiated after the database can be directly queried. Then I use mysqli written, out of the wrong, do not know how to solve, see the code:
This is a tool class, he is mainly to complete the direct operation of MySQL
Class sqlhelper{
Public $hosts;
public $username;
Public $password;
Public $database;
The constructor is basically the initialization of the object that completes the Mysqli
Public function __construc ($a, $b, $c, $d) {
$mysqli =new mysqli ($a, $b, $c, $d);
if ($mysqli->connect_error) {
Die ("Database connection Error! ". $mysqli->connect_error);
}
$mysqli->query ("Set names UTF8") or Die ("database set character Set error! ");
}
Here is a query method, you send me an SQL statement, I return you a two-dimensional array
Public Function Dql ($mysql) {
$res = $mysqli->query ($mysql) or Die ("Database query Error! //DQL Query statement here Returns a result set, we process the result set as a two-dimensional array, freeing the result set memory
$resarr =array ();
while ($row = $res->fetch_row ()) {//Here is the result set self-disassembly, and each time we split it into an array of arrays, we put it in a two-dimensional array
$resarr []= $row;
}
If the code goes here, indicating that the two-dimensional array has been exhausted, we immediately release the result set memory and return the two-dimensional array
$res->free ();
return $resarr;
}
Close Resource
Public Function Closeresource () {
$mysqli->close ();
}
}
?>
After instantiating an object, it is primarily a hint that the $mysqli inside the constructor is undefined, and then he is not an object, then the code behind cannot go.
notice:undefined variable:mysqli in D:\web\notebook\model\sql.php on line 30
Fatal Error:call to a member function query () on a non-object in D:\web\notebook\model\sql.php on line 30
Share to:
------Solution--------------------
Change $mysqli to $this->mysqli