What are some best practices for updating user status in a database in PHP?

When updating user status in a database in PHP, it is important to ensure that the database connection is established, the query is prepared to prevent SQL injection, and the status is updated based on the user's ID.

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

// Prepare the update query
$stmt = $pdo->prepare("UPDATE users SET status = :status WHERE id = :id");

// Bind parameters and execute the query
$stmt->bindParam(':status', $newStatus);
$stmt->bindParam(':id', $userId);
$stmt->execute();