File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ function query()
146
146
throw new Exception ('Unsuport param for query! ' , 10 );
147
147
break ;
148
148
}
149
- echo $ sql ;
149
+
150
150
if ($ param )
151
151
{
152
152
$ sth = $ this ->pdo ->prepare ($ sql , array (PDO ::ATTR_CURSOR => PDO ::CURSOR_FWDONLY ));
@@ -219,6 +219,21 @@ function insert($data)
219
219
return $ this ->table_key ? $ this ->db ->lastInsertId () : null ; //有主键返回主键值
220
220
}
221
221
222
+ //替换
223
+ function replace ($ data ){
224
+ $ set = $ this ->build_query ($ data );
225
+ if ($ set ){
226
+ $ sql = 'REPLACE INTO ` ' .$ this ->table_name .'` SET ' . implode (', ' , $ set [0 ]);
227
+
228
+ $ this ->db ->query ($ sql , $ set [1 ]);
229
+
230
+ return $ this ->table_key ? $ this ->db ->lastInsertId () : null ; //有主键返回主键值
231
+ }
232
+
233
+ return null ;
234
+
235
+ }
236
+
222
237
//查询
223
238
function query ($ where ){
224
239
$ where = $ this ->offset_parse ($ where );
Original file line number Diff line number Diff line change 2
2
require 'db.php ' ;
3
3
4
4
$ db = new db ('mysql:host=127.0.0.1;dbname=test ' , 'root ' , 'root ' );
5
-
6
- var_dump (count ($ db ['t1 ' ]->where (array ('id:> ' =>0 ))));
5
+ $ db ['t1 ' ]->replace (array ('id ' =>7 , 'value ' =>14 ));
7
6
8
7
You can’t perform that action at this time.
0 commit comments