$table = 'users'; $column_values = array('username' => 'new_username', 'password' => 'new_password'); $condition = "id = 1"; $query = "UPDATE $table SET "; foreach ($column_values as $column => $value) { $query .= "$column = '$value',"; } $query = rtrim($query, ",") . " WHERE $condition;"; mysqli_query($connection, $query);
$table = 'employees'; $column_values = array('salary' => 60000); $condition = "department = 'Marketing'"; $query = \DB::table($table)->where($condition)->update($column_values);In this example, we are updating the salary of all employees in the Marketing department to $60,000. This code uses Laravel’s Eloquent ORM (Object-Relational Mapping) library. In conclusion, the package library used in these examples varies based on the needs of the project. The first example uses mysqli, while the second uses Laravel’s Eloquent ORM.