Perbarui Data Data Beberapa Kolom MySQL Database Tabel Fungsi PHP

function updateDataFromTable($table, $where, ...$params): bool
{
    global $db;
    $sql = "UPDATE $table SET ";
    foreach ($params[0] as $key => $val) {
        if ($val != 'NULL') {
            $sql .= "`{$key}`=" . "'{$val}' ,";
        } else {
            $sql .= "`{$key}`=" . ' NULL' . ",";
        }
    }
    if ($where) {
        $sql .= ' WHERE ' . $where . ' ';
    }
    $sql = substr_replace($sql, '', strrpos($sql, ','), 1);
    $result = $db->query($sql);
    //var_dump($sql);
    if ($result) {
        return true;
    } else {
        return false;
    }
}
Amin Arjmand