Small white Help: PHP database error, Fatal Error:call to a member function exec () on a non-object in

Source: Internet
Author: User
Tags php database
The previous PDO database wrapper class was sorted out today, but when used, the error Fatal Error:call to a member function exec () on a non-object in sqlcontrol.class.php on Lin E 45 This is the complete error prompt, there is no modification before the time without this error, this is how it happened.
This is the class I'm using.


   Header"Content-type:text/html;charset=utf-8"); classdbpdomanger{Private$conn='';//connection to the Database server resource typePrivate$host="";//Host addressPrivate$dbname="";//Database namePrivate$user="";//Database user namePrivate$pwd="";//PasswordPrivate$charset="";//Link encodingPrivate$config=Array();/* Constructor Initialize Database * Variable: $host connected server name * $user Login Server username * $PWD Login Server password */ Public function__construct($config) {$this->config=$config;$this->host=$this->config["Host"];$this->dbname=$this->config["DBName"];$this->user=$this->config["User"];$this->pwd=$this->config["PWD"];$this->charset=$this->config["CharSet"];//$this->open ();}/ * Open Database */ Public functionopen() {$this->conn=NewPDO ("mysql:host=".$this->host.";d bname=".$this->dbname,$this->user,$this-PWD);$this->conn->query (' Set names '.$this->charset);Echo$this->conn; }/ * * additions/deletions/changes * * Public functionexecsql($sql) {$bool=$this->conn->exec ($sql);if($bool>0)        {returntrue; }Else{returnfalse; }    }/ * Query a data */ Public functionquer($sql,$mode=pdo::fetch_assoc) {$result=$this->conn->query ($sql);$result->setfetchmode ($mode);$re=$result->fetch ();$result=NULL;return$re; }/ * Query Multiple data */ Public functionquermore($sql,$mode=pdo::fetch_assoc) {$result=$this->conn->query ($sql);$result->setfetchmode ($mode);$re=$result->fetchall ();$result=NULL;return$re; }/ * Query How many records are in the specified table * / Public functiongettabrows($key,$tableName,$where) {$sql="SELECT count (".$key.") as ' C ' from '.$tableName."where".$where."";$result=$this->conn->query ($sql);$result->setfetchmode (PDO::FETCH_ASSOC);$re=$result->fetch ();$result=NULL;returnIntval ($re[' C ']); }/ * Close database * / Public functioncloseconn() {$this->conn=NULL; }}?>

Here is the code that I call this class


    
     header("content-type:text/html;charset=utf-8");include"sqlcontrol.class.php";$config["host"]="localhost";$config["dbname"]="biaodan";$config["user"]="root";$config["pwd"]="";$config["charset"]="utf-8";$db=new dbPdoManger($config);$sql="INSERT INTO `test` (`name`, `nicheng`, `password`, `sex`, `icon`, `cardid`, `city`, `phone`, `qq`, `mail`, `liuyan`)      VALUES ('t', 't', 't', 't, 't', '1315', 'tttt', '598562', '79874564', 'tret', 'werterter')";echo$db->execSql($sql);

Ask the great God to save ...

The above describes the small white Help: PHP database error, Fatal Error:call to a member function exec () on a non-object in, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.