Example:
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
PDO::PARAM_INT
Is this parameter a kind of validation for data type? If so, why not give me an error when I pass an integer?
Example:
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
PDO::PARAM_INT
Is this parameter a kind of validation for data type? If so, why not give me an error when I pass an integer?
Just like @Oeslei said, PDO :: PARAM_INT (or STR), does not validate the type of value.
To do this in case you should use filter_var
, for example:
if (filter_var($suaVariavel, FILTER_VALIDATE_INT)) {
// válido
} else {
// inválido
}
PHP Filter: link
Any questions, leave a comment below.