Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
wfpl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b063dc4
)
db_insert() can take data as separate arguments or as an array
author
Jason Woofenden
<jason183@herkamire.com>
Thu, 28 Dec 2006 09:50:42 +0000
(
04:50
-0500)
committer
Jason Woofenden
<jason183@herkamire.com>
Thu, 28 Dec 2006 09:50:42 +0000
(
04:50
-0500)
db.php
patch
|
blob
|
history
diff --git
a/db.php
b/db.php
index
b8febdb
..
ea0a900
100644
(file)
--- a/
db.php
+++ b/
db.php
@@
-207,19
+207,24
@@
function db_get_value($table, $columns, $where = '') {
return $value;
}
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) {
function db_insert($table, $columns, $values) {
- $sql = "INSERT INTO $table ($columns) values(";
+ if(!is_array($values)) {
+ $values = func_get_args();
+ $values = array_slice($values, 2);
+ }
- $first = true;
+ $sql = '';
foreach($values as $value) {
foreach($values as $value) {
- if($first) {
- $first = false;
- } else {
- $sql .= ',';
- }
+ if($sql) $sql .= ',';
$sql .= '"' . enc_sql($value) . '"';
}
$sql .= '"' . enc_sql($value) . '"';
}
- $sql .= ')';
+
+ $sql = "INSERT INTO $table ($columns) values($sql)";
db_send_query($sql);
}
db_send_query($sql);
}