Mysqli has a problem. let's take a look at the sqlhelper. class. php & nbsp; tool class. it is mainly used to directly query the database after being instantiated. Then I used mysqli to write the code and encountered an error. I don't know how to solve it. please refer to the code: & lt ;? Php // This is a tool class. it is mainly used to directly operate mysql class & nbsp mysqli. let's take a look.
I wrote a sqlhelper. class. php tool class that can directly query databases after instantiation. Then I am using mysqli, and an error occurs. I don't know how to solve it. please refer to the code:
// This is a tool class that performs direct mysql operations.
Class SQLHelper {
Public $ hosts;
Public $ username;
Public $ password;
Public $ database;
// The constructor initializes the object of 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 ("An error occurred while setting the character set of the database! ");
}
// The following is a query method. you can send me an SQL statement and I will return a two-dimensional array.
Public function dql ($ mysql ){
$ Res = $ mysqli-> query ($ mysql) or die ("database query error! "); // The dql query statement returns a result set. we process the result set as a two-dimensional array and release the result set memory.
$ Resarr = array ();
While ($ row = $ res-> fetch_row () {// Here is the result set self-split, and each split generates an array line, we put it in a two-dimensional array.
$ Resarr [] = $ row;
}
// If the code goes here, it indicates that the two-dimensional array has been obtained, and we immediately release the result set memory and return the two-dimensional array
$ Res-> free ();
Return $ resarr;
}
// Close the resource
Public function closeresource (){
$ Mysqli-> close ();
}
}
?>
After an object is instantiated, it mainly prompts that $ mysqli in the constructor is not defined, and then it is not an object, so no code can be followed.
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:
------ Solution --------------------
Change $ mysqli to $ this-> mysqli