How does using bindParam with PDO::PARAM_INT differ from using a placeholder directly in the SQL query?

When using bindParam with PDO::PARAM_INT, you are explicitly telling PDO that the parameter should be treated as an integer. This helps prevent SQL injection attacks and ensures that the value is properly formatted in the query. On the other hand, using a placeholder directly in the SQL query without specifying the parameter type leaves the possibility of incorrect data types being passed or potential security vulnerabilities.

// Using bindParam with PDO::PARAM_INT
$stmt = $pdo->prepare('SELECT * FROM table WHERE id = :id');
$id = 123;
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();