What are the best practices for handling integer values in prepared statements with PDO?

When handling integer values in prepared statements with PDO, it is important to bind the integer values using the PDO::PARAM_INT parameter type to ensure that the values are treated as integers and not as strings. This helps prevent SQL injection attacks and ensures that the values are properly sanitized before being executed in the database query.

// Example of binding an integer value in a prepared statement with PDO
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
$id = 123; // integer value
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);