Yes. Casting to int prevents all the unpleasant features of SQL injection.
If the variable was a string, you should use prepared statements to pass it.
$sql = 'SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour';
$sth = $dbh->prepare($sql);
$sth->execute(array(':calories' => 150, ':colour' => 'red'));
$red = $sth->fetchAll();
source
share