-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyDbStorage.php
More file actions
55 lines (47 loc) · 1.3 KB
/
MyDbStorage.php
File metadata and controls
55 lines (47 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace MyNamespace\Queue2Config;
use iry\queue\storage\Db;
use iry\queue\Store\Redis;
//e.g. 1 示例 1
//'\MyNamespace\MyDbStorage?dsn=my-table-name';
class MyDbStorage extends Db
{
private $_db;
protected function _init($args, $rawArgs)
{
parent::_init($args, $rawArgs);
$username = isset($args["username"])?$args["username"]:null;
$password = isset($args["password"])?$args["password"]:null;
$this->_db = new \PDO($args['dsn'],$username,$password);
}
/**
* @param string $sql
* @return array
*/
protected function _query($sql)
{
//query sql
$sth = $this->_db->prepare($sql);
if($sth) {
$sth->execute();
$_result = $sth->fetchAll(\PDO::FETCH_CLASS);
if(!empty($_result)){
foreach ($_result as &$v) {
if (is_object($v)) {
$v = get_object_vars($v);
}
}unset($v);
}
return $_result;
}
return [];
}
/**
* @param string $sql
* @param string $sqlType
* @return bool
*/
protected function _exec($sql,$sqlType){
return $this->_db->exec($sql);
}
}