Skip to content

Commit 1da1304

Browse files
committed
Merge pull request #3 from liu21st/master
merge
2 parents 3bf6930 + b9ce614 commit 1da1304

File tree

2 files changed

+382
-333
lines changed

2 files changed

+382
-333
lines changed

Extend/Driver/Db/DbPdo.class.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ public function free() {
8383
* 执行查询 返回数据集
8484
* @access public
8585
* @param string $str sql指令
86+
* @param array $bind 参数绑定
8687
* @return mixed
8788
*/
88-
public function query($str) {
89+
public function query($str,$bind=array()) {
8990
$this->initConnect(false);
9091
if ( !$this->_linkID ) return false;
9192
$this->queryStr = $str;
93+
if(!empty($bind)){
94+
$this->queryStr .= '[ '.print_r($bind,true).' ]';
95+
}
9296
//释放前次的查询结果
9397
if ( !empty($this->PDOStatement) ) $this->free();
9498
N('db_query',1);
@@ -97,7 +101,7 @@ public function query($str) {
97101
$this->PDOStatement = $this->_linkID->prepare($str);
98102
if(false === $this->PDOStatement)
99103
throw_exception($this->error());
100-
$result = $this->PDOStatement->execute();
104+
$result = $this->PDOStatement->execute($bind);
101105
$this->debug();
102106
if ( false === $result ) {
103107
$this->error();
@@ -111,12 +115,16 @@ public function query($str) {
111115
* 执行语句
112116
* @access public
113117
* @param string $str sql指令
118+
* @param array $bind 参数绑定
114119
* @return integer
115120
*/
116-
public function execute($str) {
121+
public function execute($str,$bind=array()) {
117122
$this->initConnect(true);
118123
if ( !$this->_linkID ) return false;
119124
$this->queryStr = $str;
125+
if(!empty($bind)){
126+
$this->queryStr .= '[ '.print_r($bind,true).' ]';
127+
}
120128
$flag = false;
121129
if($this->dbType == 'OCI')
122130
{
@@ -134,7 +142,7 @@ public function execute($str) {
134142
if(false === $this->PDOStatement) {
135143
throw_exception($this->error());
136144
}
137-
$result = $this->PDOStatement->execute();
145+
$result = $this->PDOStatement->execute($bind);
138146
$this->debug();
139147
if ( false === $result) {
140148
$this->error();
@@ -423,6 +431,27 @@ public function escapeString($str) {
423431
}
424432
}
425433

434+
/**
435+
* value分析
436+
* @access protected
437+
* @param mixed $value
438+
* @return string
439+
*/
440+
protected function parseValue($value) {
441+
if(is_string($value)) {
442+
$value = strpos($value,':') === 0 ? $this->escapeString($value) : '\''.$this->escapeString($value).'\'';
443+
}elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){
444+
$value = $this->escapeString($value[1]);
445+
}elseif(is_array($value)) {
446+
$value = array_map(array($this, 'parseValue'),$value);
447+
}elseif(is_bool($value)){
448+
$value = $value ? '1' : '0';
449+
}elseif(is_null($value)){
450+
$value = 'null';
451+
}
452+
return $value;
453+
}
454+
426455
/**
427456
* 获取最后插入id
428457
* @access public

0 commit comments

Comments
 (0)