How can integers be handled securely in PHP when inserting them into SQL queries?

When inserting integers into SQL queries in PHP, it is important to sanitize the input to prevent SQL injection attacks. One way to do this is by using prepared statements with parameterized queries, which separate the SQL query from the user input. This ensures that the integer values are treated as data rather than executable SQL code.

// Assuming $conn is the database connection object
$int_value = 42; // Integer value to be inserted

$stmt = $conn->prepare("INSERT INTO table_name (int_column) VALUES (?)");
$stmt->bind_param("i", $int_value);
$stmt->execute();