optional parameter to not warn about empty params to database queries
Hanno

Hanno commited on 2018-07-23 15:39:24
Zeige 2 geänderte Dateien mit 6 Einfügungen und 6 Löschungen.

... ...
@@ -39,10 +39,10 @@ class DB extends PDO
39 39
     /*
40 40
       Wenn Parameter übergeben werden, werden Queries immer als Prepared statements übertragen
41 41
     */
42
-    public function query($stmt, $params = null)
42
+    public function query($stmt, $params = null, $allowempty = false)
43 43
     {
44 44
         if (is_array($params)) {
45
-            if (config("enable_debug")) {
45
+            if (config("enable_debug") && !$allowempty) {
46 46
                 foreach (array_values($params) as $p) {
47 47
                     if ($p === '') {
48 48
                         DEBUG("Potential bug, empty string found in database parameters");
... ...
@@ -121,7 +121,7 @@ function __ensure_connected()
121 121
 }
122 122
 
123 123
 
124
-function db_query($stmt, $params = null)
124
+function db_query($stmt, $params = null, $allowempty = false)
125 125
 {
126 126
     global $_db;
127 127
     __ensure_connected();
... ...
@@ -131,7 +131,7 @@ function db_query($stmt, $params = null)
131 131
         DEBUG($params);
132 132
     }
133 133
     try {
134
-        $result = $_db->query($stmt, $params);
134
+        $result = $_db->query($stmt, $params, $allowempty);
135 135
         DEBUG('=> '.$result->rowCount().' rows');
136 136
     } catch (PDOException $e) {
137 137
         global $debugmode;
... ...
@@ -598,11 +598,11 @@ function save_alias($alias)
598 598
     if ($id == 0) {
599 599
         unset($args[":id"]);
600 600
         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
601
-        db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args);
601
+        db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args, true);
602 602
     } else {
603 603
         unset($args[":vhost"]);
604 604
         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
605
-        db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args);
605
+        db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args, true);
606 606
     }
607 607
 }
608 608
 
609 609