php7.0取消mysql拓展,所以使用PDO类

<?php 
header("Content-type:text/html;charset=utf-8");
class DBO{
    private $dbh;
    public function __construct(){
        $dsn = 'mysql:dbname=dh;host=127.0.0.1';
        $user = 'root';
        $password = '';
        try {
            $this->dbh = new PDO($dsn, $user, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
        } catch (PDOException $e) {
            echo 'Connection failed: ' . $e->getMessage();
        }
    }
    //取出一条数据
    public function sRow($sql){
        $sth = $this->dbh->prepare($sql);
        $sth->execute();
        $ret = $sth->fetchAll(PDO::FETCH_ASSOC);
        return $ret[0];
    }
    //取出所有数据
    public function sRows($sql){
        $sth = $this->dbh->prepare($sql);
        $sth->execute();
        return $sth->fetchAll(PDO::FETCH_ASSOC);
    }
    
    //insert update deletes
    public function dbIUD($sql){
        $sth = $this->dbh;
        $count = $sth->exec($sql);
        if($count){
            return true;
        }else {
            return false;
        }
    }
}
$db=new DBO();//实例化
$sql="update serve set uncondition_refund='10'";
$res=$db->dbIUD($sql);
var_dump($res);
?>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值