]> git.mxchange.org Git - mailer.git/blobdiff - inc/sql-functions.php
Extension ext-network continued:
[mailer.git] / inc / sql-functions.php
index 6298ed43f4efc2bd3569d26379773302e4fc7766..5ec4bee18cf0ce1fdfc51ba08946e48dc4850b0a 100644 (file)
@@ -171,5 +171,39 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e
        return $SQL;
 }
 
+// "Getter" for an "INSERT INTO" SQL query
+function getInsertSqlFromArray ($array, $tableName, $excludedFields = array('ok', 'add', 'do_edit')) {
+       // Init SQL
+       $SQL = 'INSERT INTO
+`{?_MYSQL_PREFIX?}_' . $tableName . '`
+(
+`' . implode('`,`', array_keys(postRequestArray())) . '`
+) VALUES (';
+
+       // Walk through all entries
+       foreach (postRequestArray() as $key=>$value) {
+               // Add all entries
+               if (is_null($value)) {
+                       // Add NULL
+                       $SQL .= 'NULL,';
+               } elseif ((bigintval($value, true, false) == $value)) {
+                       // Number detected, no need for ticks (')
+                       $SQL .= bigintval($value) . ',';
+               } elseif ('' . (float)$value . '' == $value) {
+                       // Float number detected
+                       $SQL .= sprintf('%01.5f', $value);
+               } else {
+                       // Everything else might be a string, so add ticks around it
+                       $SQL .= "'" . SQL_ESCAPE($value) . "',";
+               }
+       } // END - foreach
+
+       // Finish SQL query
+       $SQL .= ')';
+
+       // Return SQL query
+       return $SQL;
+}
+
 // [EOF]
 ?>