PHP PDO demo
<?php class DB { private $pdo = null; public function __construct($host, $database, $user, $password) { try { $this->pdo = new PDO("mysql:host=$host;dbname=$database", $user, $password); } catch (PDOException $e) { echo 'Connect Database Exception:' . $e->getMessage(); } } public function findOne($sql, $params = null) { $statement = $this->pdo->prepare($sql); $statement->execute($params); return $statement->fetch(PDO::FETCH_ASSOC); } public function findAll($sql, $params = null) { $statement = $this->pdo->prepare($sql); $statement->execute($params); return $statement->fetchAll(PDO::FETCH_ASSOC); } public function findSingle($sql, $params = null) { $statement = $this->pdo->prepare($sql); $statement->execute($params); return $statement->fetchColumn(0); } public function execute($sql, $params = null) { $statement = $this->pdo->prepare($sql); return $statement->execute($params); } public function quote($var) { return $this->pdo->quote($var); } public function beginTransaction() { $this->pdo->beginTransaction(); } public function commit() { $this->pdo->commit(); } public function rollBack() { $this->pdo->rollBack(); } }
相关推荐
王志龙 2020-05-15
klarclm 2020-04-21
jkzyx 2020-05-04
igogo00 2020-02-13
stefan0 2019-12-20
huolan 2020-01-09
newfarhui 2019-12-24
暗夜之城 2019-12-06
airfling 2019-11-25
jackYangyang 2019-11-04
whucaodi 2019-11-18
shellching 2007-10-23
hebiwtc 2007-08-30
sinlff 2009-01-20
DAV数据库 2019-10-21
xcguoyu 2019-10-21
zbcaicai 2019-10-21