Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/PicoDb/StatementHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,36 @@ protected function bindParams(PDOStatement $pdoStatement)
}

foreach ($this->positionalParams as $value) {
$pdoStatement->bindValue($i, $value, PDO::PARAM_STR);
switch (true) {
case is_numeric($value):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_numeric will return true if:

  • Value is a string containing a numeric value
  • Value is an int
  • Value is a float

Since PDO only has a param type for ints specifically and we want to allow int-only values in actual strings, is_int should be used here instead. This means floats and strings containing numeric values are still bound as strings.

$pdoStatement->bindValue($i, $value, PDO::PARAM_INT);
break;
case is_bool($value):
$pdoStatement->bindValue($i, $value, PDO::PARAM_BOOL);
break;
case $value === null:
$pdoStatement->bindValue($i, $value, PDO::PARAM_NULL);
break;
default:
$pdoStatement->bindValue($i, $value, PDO::PARAM_STR);
}
$i++;
}

foreach ($this->namedParams as $name => $value) {
$pdoStatement->bindValue($name, $value, PDO::PARAM_STR);
switch (true) {
case is_numeric($value):
$pdoStatement->bindValue($name, $value, PDO::PARAM_INT);
break;
case is_bool($value):
$pdoStatement->bindValue($name, $value, PDO::PARAM_BOOL);
break;
case $value === null:
$pdoStatement->bindValue($i, $value, PDO::PARAM_NULL);
break;
default:
$pdoStatement->bindValue($name, $value, PDO::PARAM_STR);
}
}
}

Expand Down