您的位置 >>> 星想互联 >>> 编程技术 >>> PHP高级编程
pdo封装类实例
点击数:87  发布时间2018-04-24 09:32:43
<?php 
class mypdo{
private $host;
private $dbname;
private $user;
private $password;
public $char;

public $link;

public function __construct($host,$dbname,$user,$password,$char){
$this->host=$host;
$this->dbname=$dbname;
$this->user=$user;
$this->password=$password;
$this->char=$char;

$this->conn();
}

public function conn(){
$this->link=new PDO("mysql:host=$this->host;dbname=$this->dbname","$this->user","$this->password");
$this->link->query("set names utf8");
}

public function query($sql){
return $this->link->query($sql);

}

public function getone($sql){
return $this->query($sql)->fetch();
}

public function getall($sql){
return $this->query($sql)->fetchAll();
}

public function prepare($sql,$arr){
return $this->link->prepare($sql)->execute($arr);
}
}
$pdo=new mypdo("localhost","news","root","","utf8");

 ?>
来源:咸宁网站建设