0

I sometimes see:

$data = $connection->prepare("sql query...");
$data->bindValue(":my_var_to_replace", $foobar, PDO::PARAM_INT);
$data->execute();

but other people simply ommit PDO::PARAM_INT and place the data as an array inside execute (as argument).

Which is preferred? Can it be omitted inside bindValue?

wonderwhy
  • 393
  • 2
  • 19
  • 1
    If you omit it, PDO will use `PDO::PARAM_STR` and treat everything as a string. Sometimes that's fine, other times you want to be more specific. (now thinking of a good specific example of when it matters...) – Michael Berkowski Jul 07 '14 at 15:41
  • In addition to the one linked at the top, [this one has more outside-the-box-thinking examples](http://stackoverflow.com/questions/7326720/variable-type-in-pdostatementbindvalue) – Michael Berkowski Jul 07 '14 at 15:44
  • Aha! [And this one as well](http://stackoverflow.com/questions/5793340/reasons-to-strongly-type-parameters-in-pdo). The `LIMIT` use case is one you might regularly encounter. – Michael Berkowski Jul 07 '14 at 15:45
  • @MichaelBerkowski ok thanks, those ones are good. – wonderwhy Jul 07 '14 at 15:56

0 Answers0