Skip to content

Commit

Permalink
Merge dbUpdate and dbInsert from another branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Nov 18, 2024
1 parent efe16fd commit 16a5f9e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions web/includes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,36 @@ function db_supports_feature($feature) {
ZM\Warning("Unknown feature requested $feature");
}
}

function dbInsert($table, $fieldArray) {
$query = 'INSERT INTO `' . $table . '` SET ';
$fields = [];
$conditions = [];
$values = [];
foreach ($fieldArray as $fieldName => $fieldValue) {
$fields[] = '`' . $fieldName.'`=?';
$values[] = $fieldValue;
}
$query .= implode(', ', $fields);
return dbQuery($query, $values);
}

function dbUpdate($table, $fieldArray, $conditionArray) {
$query = 'UPDATE `' . $table . '` SET ';
$fields = [];
$conditions = [];
$values = [];
foreach ($fieldArray as $fieldName => $fieldValue) {
$fields[] = '`' . $fieldName.'`=?';
$values[] = $fieldValue;
}
$query .= implode(', ', $fields);
$query .= ' WHERE ';
foreach ($conditionArray as $fieldName => $fieldValue) {
$conditions[] = '`' . $fieldName . '` = ?';
$values[] = $fieldValue;
}
$query .= implode(' AND ', $conditions);
return dbQuery($query, $values);
}
?>

0 comments on commit 16a5f9e

Please sign in to comment.