JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
db_insert() can take data as separate arguments or as an array
[wfpl.git] / db.php
diff --git a/db.php b/db.php
index 89e972e..ea0a900 100644 (file)
--- a/db.php
+++ b/db.php
@@ -207,4 +207,26 @@ function db_get_value($table, $columns, $where = '') {
        return $value;
 }
 
+# call either of these ways:
+#
+# db_insert('people', 'name,company', 'jason', 'widgets ltd');
+# or
+# db_insert('people', 'name,company', array('jason', 'widgets ltd'));
+function db_insert($table, $columns, $values) {
+       if(!is_array($values)) {
+               $values = func_get_args();
+               $values = array_slice($values, 2);
+       }
+
+       $sql = '';
+       foreach($values as $value) {
+               if($sql) $sql .= ',';
+               $sql .= '"' . enc_sql($value) . '"';
+       }
+
+       $sql = "INSERT INTO $table ($columns) values($sql)";
+
+       db_send_query($sql);
+}
+
 ?>