Php uses the mysqli module to connect to the database Fatalerror: Calltoamemberfunctionquery (). Solution

Source: Internet
Author: User
Php uses the mysqli module to connect to the database Fatalerror: Calltoamemberfunctionquery ().... This error occurs: Fatalerror: Calltoamemberfunctionquery () onanon-php using the mysqli module to connect to the database Fatal error: Call to a member function query ()....
This error occurs: 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 "an error occurred while connecting to the item database! ";}} Public function close () {if ($ this-> mysqli) $ this-> mysqli-> close (); $ this-> mysqli = FALSE ;} public function _ destruct () {$ this-> close () ;}} class UserDB extends Database {public function queryUserByName ($ name) {$ query = "SELECT * FROM Users WHERE name = '". $ name. "'"; if ($ result = $ this-> mysqli-> query ($ query) // An error is prompted here !! Return true; else return false ;}


Then, the above class object is called on 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 underlines

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.