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