hustnaive / pdo-db
该包最新版本(dev-master)的许可信息不可用。
dev-master
2016-05-19 08:51 UTC
Requires
- php: >=5.5
This package is not auto-updated.
Last update: 2024-09-20 19:31:20 UTC
README
pdo-db基于PDO API进行二次封装,主要封装了一些常见的CRUD操作,避免自己编写SQL语句。关于PDO库的使用,请参考:https://php.ac.cn/manual/zh/book.pdo.php
同时,这个封装参考了yii的db的API接口方式,熟悉yii的db-api的人可以较快上手。
用法
composer require --dev "hustnaive/pdo-db"
实例
$db = new \fangl\db\Connection($dsn, $username, $password);
目前只测试了以mysql:开头的dsn,其他的没有经过测试,如果大家在测试中遇到bug,可以告诉我。
查询
$db->createCommand($sql,$params=[])->queryXXX();
$db->createCommand('select * from dual where id = :ID',[':ID'=>1])->queryOne();
$db->createCommand('select * from dual')->queryAll();
$db->createCommand('select id from dual')->queryColumn();
执行
$db->createCommand($sql,$params=[])->execute();
CRUD
$db->createCommand()->insert($table,$columns)->execute();
$db->createCommand()->update($table,$columns,$condition,$params=[])->execute();
$db->createCommand()->delete($table,$condtion,$params)->execute();
$db->createCommand()->truncateTable($table)->execute();
$db->createCommand()->batchInsert($table,$data,$fields);
事务
$db->beginTransaction();
//do some thing
if($isOk) {
$db->commit();
}
else {
$db->rollback();
}