git.shiar.nl
/
minimedit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
issue: database insert method to keep array values
[minimedit.git]
/
database.inc.php
diff --git
a/database.inc.php
b/database.inc.php
index 218335814bebf8e993aeb034449d7dc17efae940..464126b3fad1370fe17f6e32dd4863a92dd759a5 100644
(file)
--- a/
database.inc.php
+++ b/
database.inc.php
@@
-22,13
+22,24
@@
class DB
return $stmt;
}
return $stmt;
}
+ function _value($val, &$params)
+ {
+ $params[] = $val;
+ return '?';
+ }
+
function insert($table, $row)
{
function insert($table, $row)
{
+ $params = [];
+ $cols = [];
+ foreach ($row as $col => $val) {
+ $cols[] = $this->_value($val, $params);
+ }
$sql = sprintf('INSERT INTO %s (%s) VALUES (%s)',
'"'.$table.'"',
implode(', ', array_keys($row)),
$sql = sprintf('INSERT INTO %s (%s) VALUES (%s)',
'"'.$table.'"',
implode(', ', array_keys($row)),
- implode(', ',
array_fill(0, count($row), '?')
)
+ implode(', ',
$cols
)
);
);
- return $this->query($sql,
array_values($row)
);
+ return $this->query($sql,
$params
);
}
}
}
}