How PDO :: PARAM_STR parameter works in PHP + PDO

2

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?

    
asked by anonymous 11.06.2015 / 22:00

1 answer

1

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
}

Useful links

PHP Filter: link

Any questions, leave a comment below.

    
11.06.2015 / 22:28