调用-自己写的一个php的PDO的类,有点问题,求大神指点

WBOY
Release: 2016-06-02 11:33:02
Original
800 people have browsed it

php调用数据库

自己写的一个php的PDO的类,在调用的时候可以查询,插入的时候没有报错,但是插入没有成功,这是怎么回事。。。。。。。。。。
这个是调用的类

<code> <?php header("content-type:text/html;charset=utf-8");class dbPdoManger{    private $conn='';//连接数据库服务器的资源类型    private $host="";//主机地址    private $dbname="";//数据库名称    private $user="";//数据库用户名    private $pwd="";//密码    private $charset="";//链接编码    private $config=array();    /*     * 构造函数初始化数据库     * 变量: $host连接的服务器名称     *     $user登陆服务器的用户名     *     $pwd登陆服务器的密码     */    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();    }    /*     * 打开数据库     */    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);    }    /*     * 增删改     */    public function execSql($sql)    {        $bool=$this->conn->exec($sql);        if($bool>0)        {            return "true";        }else        {            return false;        }    }    /*     * 查询一条数据    */    public function quer($sql,$mode=PDO::FETCH_ASSOC)    {        $result=$this->conn->query($sql);        $result->setFetchMode($mode);        $re=$result->fetch();        $result=null;        return $re;    }    /*     * 查询多条数据    */    public function querMore($sql,$mode=PDO::FETCH_ASSOC)    {        $result=$this->conn->query($sql);        $result->setFetchMode($mode);        $re=$result->fetchAll();        $result=null;        return $re;    }    /*查询指定表中有多少条记录*/    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']);    }    /*关闭数据库*/    public function closeConn()    {        $this->conn=null;    }}?></code>
Copy after login

这个是调用的方法

<code> <?phpheader ("content-type:text/html;charset=utf-8");include "sqlcontrol.class.php";$config["host"]="localhost";$config["dbname"]="biaodan";$config["user"]="root";$config["pwd"]="root";$config["charset"]="utf-8";$db=new dbPdoManger($config);$db->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);</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template