Skip to content

Commit

Permalink
re-embed the binding logic in the perform() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Aug 2, 2018
1 parent 4ab243d commit c4c3bdc
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,21 @@ public function perform(
{
$sth = $this->prepare($statement);
foreach ($values as $name => $args) {
$this->bind($sth, $name, (array) $args);
}
$sth->execute();
return $sth;
}
if (is_int($name)) {
// sequential placeholders are 1-based
$name ++;
}

protected function bind(PDOStatement $sth, $name, array $args) : void
{
if (is_int($name)) {
// sequential placeholders are 1-based
$name ++;
}
settype($args, 'array');
$type = $args[1] ?? PDO::PARAM_STR;
if ($type === PDO::PARAM_BOOL && is_bool($args[0])) {
$args[0] = $args[0] ? '1' : '0';
}

// PDO does not always deal well with boolean values.
// cast to their string integer equivalents instead.
// yes, PDO seems to wants a string "0" or "1".
$type = $args[1] ?? PDO::PARAM_STR;
if ($type === PDO::PARAM_BOOL && is_bool($args[0])) {
$args[0] = $args[0] ? '1' : '0';
$sth->bindValue($name, ...$args);
}

$sth->bindValue($name, ...$args);
$sth->execute();
return $sth;
}

public function fetchAffected(
Expand Down

0 comments on commit c4c3bdc

Please sign in to comment.