Skip to content

Commit a6a094a

Browse files
author
Marius Cramer
committed
- added function to insert db data from array
1 parent 5a0b54c commit a6a094a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,27 @@ public function toLower($record) {
538538
}
539539
return $out;
540540
}
541-
541+
542+
public function insertFromArray($tablename, $data) {
543+
if(!is_array($data)) return false;
544+
545+
$k_query = '';
546+
$v_query = '';
547+
548+
$params = array($tablename);
549+
$v_params = array();
550+
551+
foreach($data as $key => $value) {
552+
$k_query .= ($k_query != '' ? ', ' : '') . '??';
553+
$v_query .= ($v_query != '' ? ', ' : '') . '?';
554+
$params[] = $key;
555+
$v_params[] = $value;
556+
}
557+
558+
$query = 'INSERT INTO ?? (' . $k_query . ') VALUES (' . $v_query . ')';
559+
return $this->query($query, true, $params + $v_params);
560+
}
561+
542562
public function diffrec($record_old, $record_new) {
543563
$diffrec_full = array();
544564
$diff_num = 0;

0 commit comments

Comments
 (0)