-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdb_update.php
More file actions
37 lines (29 loc) · 791 Bytes
/
db_update.php
File metadata and controls
37 lines (29 loc) · 791 Bytes
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
<?php
function db_process_hash($hash){
$out = array();
foreach(array_keys($hash) as $k){
$out["`$k`"] = "'$hash[$k]'";
}
return $out;
}
function db_insert($table, $hash){
global $db;
$hash = db_process_hash($hash);
$fields = implode(', ', array_keys($hash));
$data = implode(', ', $hash);
mysql_query("INSERT INTO $table ($fields) VALUES ($data)", $db);
return mysql_insert_id();
}
function db_update($table, $hash, $id){
if (!$id){ return db_insert($table, $hash); }
global $db;
$hash = db_process_hash($hash);
$data = array();
foreach(array_keys($hash) as $k){
$data[] = "$k = $hash[$k]";
}
$data = implode(', ', $data);
mysql_query("UPDATE $table SET $data WHERE id=$id", $db);
return $id;
}
?>