There are some problems with mysqli. let's take a look.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.