小白求助:自己封装的pdo类,查询功能没错,但是在插入的时候出错

今天整理了下以前的pdo数据库封装类,但是在使用的时候有点问题,链接数据库成功后,查询可以用,插入的时候会出现空白,没有错误提示,但是数据也没能插入是怎么回事。由于是自己写的,求改进意见,大神求解啊。。。。。。。。。。。。
这个是我用的类

<?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);
        echo $this->conn;
    }

    /*
     * 增删改
     */
    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;
    }
}

?>

下面是我调用这个类的代码

<?php
header("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);

$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);

求大神解救。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值