Call-Write yourself a PHP PDO class, a bit of a problem, ask the big God pointing

Source: Internet
Author: User
Keywords PHP Call Database
PHP Call Database

Write Yourself a PHP PDO class, when the call can query, insert the time without error, but the insertion did not succeed, this is how the matter ....
This is the calling class.

 
   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 Function open () {$this->conn=new PDO ("mysql:host=". $this->host. ";        Dbname= ". $this->dbname, $this->user, $this->pwd);    $this->conn->query (' Set names '. $this->charset);        }/* * additions/deletions/Public function Execsql ($sql) {$bool = $this->conn->exec ($sql);        if ($bool >0) {return "true";        }else {return false; }/* * Query a data */Public Function Quer ($sql, $mode =pdo::fetch_assoc) {$result = $this->CONN-&G        T;query ($sql);        $result->setfetchmode ($mode);        $re = $result->fetch ();        $result =null; Return$re; }/* * Query multiple Data */Public function Quermore ($sql, $mode =pdo::fetch_assoc) {$result = $this->conn-&gt        ; query ($sql);        $result->setfetchmode ($mode);        $re = $result->fetchall ();        $result =null;    return $re; }/* Query Specifies how many records are in the table */Public Function gettabrows ($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;    return intval ($re [' C ']);    }/* Close database */Public Function Closeconn () {$this->conn=null; }}?>

This is the method of invocation

 
  
    open();$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);
  • 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.