-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.php
156 lines (125 loc) · 3.04 KB
/
base.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace database;
/**
* This file is part of keenly from.
*
* @author brain_yang<[email protected]>
* (c) brain_yang
* github: https://github.com/keenlysoft/
* @time 2018年1月27日
* For the full copyright and license information, please view the LICENSE
*/
use keenly\Exception\dbException;
use database\mysql\pdoBuilder;
class base extends abstractPdo
{
public $sqlStr;
private $connection = 'connectionSql';
private $database = 'database\mysql\pdoBuilder';
private $adodb = false;
public $dh;
protected $ilink = false;
public function __construct($adodb = null, $initdb = FALSE)
{
$this->adodb = is_string($adodb) ? $adodb : false;
$this->dh = $this->init($initdb);
}
public function init($initdb = FALSE)
{
return method_exists($this->database, $this->connection) ? call_user_func_array(array(
$this->database,
$this->connection
), [
$this->adodb,
$initdb
]) : '';
}
public function exce($sql)
{
$this->sqlStr = $sql;
return $this->dh->exec($sql);
}
public function query($sql)
{
try {
$this->sqlStr = $sql;
$this->ilink = $this->dh->query($sql);
return $this;
} catch (\PDOException $e) {
var_export($sql);
throw new dbException($e, $e->getCode());
}
}
public function quote($string)
{
return $this->dh->quote($string);
}
public function execute()
{
return $this->dh->execute();
}
public function begin()
{
return $this->dh->beginTransaction();
}
// 检查是否在一个事务内
public function InTransaction()
{
return $this->dh->InTransaction();
}
public function commit()
{
return $this->dh->commit();
}
public function back()
{
return $this->dh->rollBack();
}
// 关闭游标
public function closeCursor()
{
return $this->ilink->closeCursor();
}
// 单条结果
public function one()
{
if ($this->ilink) {
$res = $this->ilink->fetch(\PDO::FETCH_ASSOC);
$this->closeCursor();
return $res;
}
}
// 多条结果
public function all()
{
if ($this->ilink) {
$res = $this->ilink->fetchAll(\PDO::FETCH_ASSOC);
$this->closeCursor();
return $res;
}
}
//
public function _isStrType($var)
{
if (is_int($var))
return 1;
return 2;
}
public function Pall($class)
{
$class->setFetchMode(\PDO::FETCH_ASSOC);
return $class->fetchAll();
}
public function Pone($class)
{
$class->setFetchMode(\PDO::FETCH_ASSOC);
return $class->fetch();
}
public function __call($func, $args)
{
return call_user_func_array(array(
&$this->dh,
$func
), $args);
}
}