What is the best way to bind decimal / double / float values with PDO in PHP?

前提是你 提交于 2020-01-09 05:20:32

问题


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 doubles.



来源:https://stackoverflow.com/questions/1335081/what-is-the-best-way-to-bind-decimal-double-float-values-with-pdo-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!