• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-25) 16次浏览 已收录 0个评论

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::FE<p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite>TCH_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>

这个是调用的方法

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

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:调用-自己写的一个php的PDO的类,有点问题,求大神指点
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址