<?php
class databasel{
private $dsx;
private $user;
private $pass;
private $pd;
function __construct($dsx,$user,$pass){
$pdo=new PDO($dsx,$user,$pass);
$this->dsx =$dsx;
$this->user =$user;
$this->pass =$pass;
$this->pd =$pdo;
$this->getAll();
}
public function getAll(){
//增
$sql='insert a values(:id,:name)';
$smt=$this->pd->prepare($sql);//返回一个PDOStatement对象
$id='10';
$name='zhangyafei';
$smt->bindParam(':id',$id);
$smt->bindParam(':name',$name);
$smt->execute();
}
public function dele($dsx,$user,$pass){
//删
$sql2='delete from a';
$dele=$this->pd->exec($sql2);
}
public function sel(){
//查
$sql = 'select * from a';
$stm = $this->pd->query($sql);
$rows = $stm ->fetchAll(PDO::FETCH_ASSOC);
var_dump($rows);
}
public function upd($a,$b){
//改
$sql1 = 'update a set name="'.$a.'" where id='.$b;
$nums = $this->pd->exec($sql1);
}
}
$dsx='mysql:host =localhost;dbname=a';
$user='root';
$pass='';
$a=new databasel($dsx,$user,$pass);
$a->upd('aaaaaaa','10');
?>
class databasel{
private $dsx;
private $user;
private $pass;
private $pd;
function __construct($dsx,$user,$pass){
$pdo=new PDO($dsx,$user,$pass);
$this->dsx =$dsx;
$this->user =$user;
$this->pass =$pass;
$this->pd =$pdo;
$this->getAll();
}
public function getAll(){
//增
$sql='insert a values(:id,:name)';
$smt=$this->pd->prepare($sql);//返回一个PDOStatement对象
$id='10';
$name='zhangyafei';
$smt->bindParam(':id',$id);
$smt->bindParam(':name',$name);
$smt->execute();
}
public function dele($dsx,$user,$pass){
//删
$sql2='delete from a';
$dele=$this->pd->exec($sql2);
}
public function sel(){
//查
$sql = 'select * from a';
$stm = $this->pd->query($sql);
$rows = $stm ->fetchAll(PDO::FETCH_ASSOC);
var_dump($rows);
}
public function upd($a,$b){
//改
$sql1 = 'update a set name="'.$a.'" where id='.$b;
$nums = $this->pd->exec($sql1);
}
}
$dsx='mysql:host =localhost;dbname=a';
$user='root';
$pass='';
$a=new databasel($dsx,$user,$pass);
$a->upd('aaaaaaa','10');
?>