Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
simple test for database client
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 3, 2017
1 parent ab9386c commit 7679cc1
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 90 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ git clone https://github.com/inhere/php-librarys.git // github
- `DataProxy.php` 简单的数据访问代理实现
- `ErrorHandler.php` 错误处理
- `Language.php` 提供语言管理,语言包处理类
- `DatabaseClient.php` 一个简单的 PDO database 操作封装
- `MemcacheClient.php` 一个简单的memcache(d)封装
- `RedisClient.php` 一个简单的 redis 操作封装
- `Pipeline.php` 一个简单的Pipeline实现封装
- **`Inhere\Library\DI`** 依赖注入容器,提供全局服务管理
- `Inhere\Library\Files` 文件系统操作(文件(夹)读取,检查,创建);
Expand Down
35 changes: 33 additions & 2 deletions examples/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,48 @@
require __DIR__ . '/s-autoload.php';

$db = DatabaseClient::make([
'debug' => 1,
'user' => 'root',
'password' => 'root',
]);

$db->on(DatabaseClient::CONNECT, function ($db) {
echo "connect database success\n";
});
$db->on(DatabaseClient::BEFORE_EXECUTE, function ($sql) {
echo "Will run SQL: $sql\n";
});
$db->on(DatabaseClient::DISCONNECT, function ($db) {
echo "disconnect database success\n";
});

$ret = $db->fetchAll('show tables');
//$ret = $db->fetchAll('show tables');
//dump_vars($ret);
//
//$ret = $db->fetchAll('select * from user');
//dump_vars($ret);

// find one
// SQL: SELECT * FROM `user` WHERE `id`= ? LIMIT 1
//$ret = $db->find('user', ['id' => 3], '*', [
// 'fetchType' => 'assoc'
//]);
//dump_vars($ret);

// find all
// SQL: SELECT * FROM `user` WHERE `username` like ? LIMIT 1000
$ret = $db->findAll('user', [ ['username', 'like', '%tes%'] ], '*', [
'fetchType' => 'assoc',
'limit' => 10
]);
dump_vars($ret);

// find all
// SQL: SELECT * FROM `user` WHERE `id` > ? ORDER BY createdAt ASC LIMIT 1000
$ret = $db->findAll('user', [['id', '>', 3]], '*', [
'fetchType' => 'assoc',
'order' => 'createdAt ASC',
]);
dump_vars($ret);

dump_vars($ret);
dump_vars($db->getQueryLog());
Loading

0 comments on commit 7679cc1

Please sign in to comment.