What is the best practice for updating multiple variables in a PHP query?

When updating multiple variables in a PHP query, it is best practice to use prepared statements to prevent SQL injection attacks and improve performance. Prepared statements separate the SQL query from the data being passed in, allowing for safer and more efficient execution.

// Example of updating multiple variables in a PHP query using prepared statements

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');

// Define the variables to update
$id = 1;
$name = 'John Doe';
$age = 30;

// Prepare the SQL query with placeholders
$stmt = $pdo->prepare('UPDATE users SET name = :name, age = :age WHERE id = :id');

// Bind the variables to the placeholders
$stmt->bindParam(':name', $name);
$stmt->bindParam(':age', $age);
$stmt->bindParam(':id', $id);

// Execute the query
$stmt->execute();