Skip to content

Commit f60f1aa

Browse files
committed
ok
1 parent 6c2cf4a commit f60f1aa

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

db.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function query()
146146
throw new Exception ('Unsuport param for query!', 10);
147147
break;
148148
}
149-
echo $sql;
149+
150150
if ($param)
151151
{
152152
$sth = $this->pdo->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
@@ -219,6 +219,21 @@ function insert($data)
219219
return $this->table_key ? $this->db->lastInsertId() : null; //有主键返回主键值
220220
}
221221

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+
222237
//查询
223238
function query($where){
224239
$where = $this->offset_parse($where);

test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require 'db.php';
33

44
$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));
76

87

0 commit comments

Comments
 (0)