2
Example:
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
PDO::PARAM_INT
This parameter is a kind of validation for data type ? If it is, why is there no error when I pass an integer?
2
Example:
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
PDO::PARAM_INT
This parameter is a kind of validation for data type ? If it is, why is there no error when I pass an integer?
1
Just like the @Oeslei said, PDO::PARAM_INT (or STR), does not validate the value type.
To do this in case you must use the filter_var
, for example:
if (filter_var($suaVariavel, FILTER_VALIDATE_INT)) {
// válido
} else {
// inválido
}
PHP Filter: http://php.net/manual/en/book.filter.php
Any questions, leave a comment below.
Browser other questions tagged php pdo
You are not signed in. Login or sign up in order to post.
I edited your code. I ask that whenever you post a question you try to identify the code (leave 1 blank line after the text, and then add 4 spaces before the code "so that it is interpreted as code", or just select the code and then click on the editor
{ }
. Other than that: you mentioned PARAM_STR, but in his question was PARAM_INT. Which one is right?– Patrick Maciel
It is not a validation. PDO uses this parameter to identify how to mount the query correctly. For example, strings should be in quotes, no longer numbers.
– Oeslei
I haven’t seen an official explanation for this yet, in practice it’s exactly as @Oeslei said. I only saw the difference to use the clásula limit
– rray