PDO bind data type and comparison
I have an integer column in a table and when I do a comparison the following code seems to work.
$myLimit = 10;
开发者_如何学JAVA$sth = $db->prepare("SELECT * FROM table WHERE number<:myLimit");
$sth->bindParam(':myLimit',$myLimit); // default datatype is PDO::PARAM_STR
$sth->execute();
$result = $sth->fetchAll();
Should I be using PDO::PARAM_INT for the third parameter for bindParam? Also what about real numbers I can't use PDO::PARAM_INT for them as it will round them.
Number handling in PHP is notoriously bad. To pass big numbers around, my advice would be to keep them as strings.
Edit I've just tested the number handling; PARAM_INT
works fine for large numeric strings, so you don't have to use PARAM_INT
but there's no harm in being precise :)
As for floats, you should pass them using PARAM_STR
to massively lose precision.
精彩评论