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.