How can SQL injection vulnerabilities be prevented when updating database values in PHP?

SQL injection vulnerabilities can be prevented when updating database values in PHP by using prepared statements with parameterized queries. This approach ensures that user input is treated as data rather than executable SQL code, thus preventing malicious SQL injection attacks.

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

// Prepare a SQL statement with placeholders
$stmt = $pdo->prepare('UPDATE table SET column = :value WHERE id = :id');

// Bind the parameters with user input
$stmt->bindParam(':value', $value);
$stmt->bindParam(':id', $id);

// Execute the prepared statement
$stmt->execute();