19

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.

Rob
  • 909
  • 1
  • 8
  • 14

3 Answers3

13

AFAIK PDO::PARAM_STR is the way to go.

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
1

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

Community
  • 1
  • 1
-4

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.

Ankur
  • 2,171
  • 23
  • 29
Kennethvr
  • 2,660
  • 5
  • 26
  • 35
  • I don't think I'd want to lose precision by binding it as an INT but you make a good point about just not specifying the type, thanks. – Rob Aug 26 '09 at 14:42
  • 12
    Actually, if no param_TYPE is given then PARAM_STR is assumed. – Xeoncross Dec 05 '09 at 19:24
  • You don't have and shouldn't bind it as integer or you will lose data! Read @AlixAxel answer instead. – PhoneixS Jun 25 '14 at 16:36