Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 901
Rob Avatar asked Aug 26 '09 14:08

Rob


2 Answers

AFAIK PDO::PARAM_STR is the way to go.

like image 89
Alix Axel Avatar answered Sep 29 '22 07:09

Alix Axel


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

like image 1
Dan Blaisdell Avatar answered Sep 26 '22 07:09

Dan Blaisdell