@@ -83,12 +83,16 @@ public function free() {
83
83
* 执行查询 返回数据集
84
84
* @access public
85
85
* @param string $str sql指令
86
+ * @param array $bind 参数绑定
86
87
* @return mixed
87
88
*/
88
- public function query ($ str ) {
89
+ public function query ($ str, $ bind = array () ) {
89
90
$ this ->initConnect (false );
90
91
if ( !$ this ->_linkID ) return false ;
91
92
$ this ->queryStr = $ str ;
93
+ if (!empty ($ bind )){
94
+ $ this ->queryStr .= '[ ' .print_r ($ bind ,true ).' ] ' ;
95
+ }
92
96
//释放前次的查询结果
93
97
if ( !empty ($ this ->PDOStatement ) ) $ this ->free ();
94
98
N ('db_query ' ,1 );
@@ -97,7 +101,7 @@ public function query($str) {
97
101
$ this ->PDOStatement = $ this ->_linkID ->prepare ($ str );
98
102
if (false === $ this ->PDOStatement )
99
103
throw_exception ($ this ->error ());
100
- $ result = $ this ->PDOStatement ->execute ();
104
+ $ result = $ this ->PDOStatement ->execute ($ bind );
101
105
$ this ->debug ();
102
106
if ( false === $ result ) {
103
107
$ this ->error ();
@@ -111,12 +115,16 @@ public function query($str) {
111
115
* 执行语句
112
116
* @access public
113
117
* @param string $str sql指令
118
+ * @param array $bind 参数绑定
114
119
* @return integer
115
120
*/
116
- public function execute ($ str ) {
121
+ public function execute ($ str, $ bind = array () ) {
117
122
$ this ->initConnect (true );
118
123
if ( !$ this ->_linkID ) return false ;
119
124
$ this ->queryStr = $ str ;
125
+ if (!empty ($ bind )){
126
+ $ this ->queryStr .= '[ ' .print_r ($ bind ,true ).' ] ' ;
127
+ }
120
128
$ flag = false ;
121
129
if ($ this ->dbType == 'OCI ' )
122
130
{
@@ -134,7 +142,7 @@ public function execute($str) {
134
142
if (false === $ this ->PDOStatement ) {
135
143
throw_exception ($ this ->error ());
136
144
}
137
- $ result = $ this ->PDOStatement ->execute ();
145
+ $ result = $ this ->PDOStatement ->execute ($ bind );
138
146
$ this ->debug ();
139
147
if ( false === $ result ) {
140
148
$ this ->error ();
@@ -423,6 +431,27 @@ public function escapeString($str) {
423
431
}
424
432
}
425
433
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
+
426
455
/**
427
456
* 获取最后插入id
428
457
* @access public
0 commit comments