commit 850e8448412ae05434955685df858f57f5e710bf
parent 7b5642b2004dccd19da36d4a3c491db45a6a7145
Author: Claudio Alessi <smoppy@gmail.com>
Date: Sun, 7 Feb 2016 20:27:06 +0100
Improve dbupd().
The function now can take an array of IDS. It also handle properly NULL and CURRENT_TIMESTAMP. More will come if needed.
Diffstat:
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/bored.php b/bored.php
@@ -201,17 +201,24 @@ function dbins($tbl, $info) {
return dbquery($sql);
}
-function dbupd($tbl, $info, $id) {
+function dbupd($tbl, $info, $ids = NULL) {
$vals = [];
foreach($info as $k => $v) {
$v = dbin($v);
if($v == NULL)
- $vals[] = "`$k`= NULL";
- else
- $vals[] = "`$k`= '$v'";
+ $v = 'NULL';
+ if($v != 'NULL' && $v != 'CURRENT_TIMESTAMP')
+ $v = "'$v'";
+ $vals[] = "`$k` = $v";
}
$vals = implode(',', $vals);
- $sql = "update `$tbl` set $vals where id = $id";
+ $sql = "update `$tbl` set $vals";
+ if($ids) {
+ if(is_array($ids))
+ $sql .= " where id IN(".implode(',', $ids).")";
+ else
+ $sql .= " where id = $ids";
+ }
return dbquery($sql);
}
@@ -547,9 +554,8 @@ function bored_init() {
dbopen(DBHOST, DBUSER, DBPASS, DBNAME);
register_shutdown_function(function() {
global $dblink;
- if(!$dblink)
- return;
- mysqli_close($dblink);
+ if($dblink)
+ mysqli_close($dblink);
session_write_close();
});
}