What are some best practices for updating the status of a record in a database using PHP?

When updating the status of a record in a database using PHP, it is important to follow best practices to ensure data integrity and security. One common approach is to use prepared statements to prevent SQL injection attacks and to sanitize user input before updating the database record.

<?php

// Assuming $status is the new status value and $recordId is the ID of the record to update

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

// Prepare the SQL statement
$sql = "UPDATE records SET status = :status WHERE id = :recordId";
$stmt = $pdo->prepare($sql);

// Bind parameters
$stmt->bindParam(':status', $status);
$stmt->bindParam(':recordId', $recordId);

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

// Close the connection
$pdo = null;

?>