问题
It appears the class constants only cover PDO::PARAM_BOOL
, PDO::PARAM_INT
and PDO::PARAM_STR
for binding. Do you just bind decimal / float / double values as strings or is there a better way to treat them?
MySQLi allows the 'd' type for double, it's surprising that PDO doesn't have an equivalent when it seems better in so many other ways.
回答1:
AFAIK PDO::PARAM_STR is the way to go.
回答2:
You have to use PDO::PARAM_STR, but for SQLite and other engines this can have unpredictable behaviors. See this issue for one example: SQLite HAVING comparison error
回答3:
If you really want to use PDO you'll have to enter it as an PARAM_INT
, but I never use a specification for double
.
It is an optional parameter to specify the PDO
type.
I guess you would better not set the PDO
type for double
s.
来源:https://stackoverflow.com/questions/1335081/what-is-the-best-way-to-bind-decimal-double-float-values-with-pdo-in-php