6

What's the point of using explicit data types in PDO::bindValue()?

For example in either of the following forms there would be an SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'a'

$pdos->bindValue(':Value_For_An_Int_Col', 'a');//default arg for the third and opt par is  PDO::PARAM_INT

$pdos->bindValue(':Value_For_An_Int_Col', 'a', PDO::PARAM_INT);
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
MTVS
  • 2,046
  • 5
  • 26
  • 37

1 Answers1

3

When you need something like

SELECT * FROM ... LIMIT :intValues

That avoids to enclose the value inside quote, rising a SQL syntax error

dynamic
  • 46,985
  • 55
  • 154
  • 231
  • This answer is wrong. Quotes are not needed, even when binding strings. – KIKO Software Mar 04 '15 at 22:09
  • pdo will insert quoted parameters and the limit will not work – dynamic Mar 04 '15 at 23:11
  • Just to be absolutely sure, I tested it. No, it does not insert quoted parameters. Could this be a version issue? You might have been right in the past, although I don't think so. To be more verbose: You do not need to specify the data types in PDO::bindValue() explicitly for it to work just fine with string and integer parameters. – KIKO Software Mar 04 '15 at 23:40