diff --git a/src/Database/ResultSet.php b/src/Database/ResultSet.php index 1783bd945..04b5e2330 100644 --- a/src/Database/ResultSet.php +++ b/src/Database/ResultSet.php @@ -64,9 +64,15 @@ public function __construct(Connection $connection, $queryString, array $params) if (substr($queryString, 0, 2) === '::') { $connection->getPdo()->{substr($queryString, 2)}(); } elseif ($queryString !== NULL) { + static $types = array('boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, + 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL); $this->pdoStatement = $connection->getPdo()->prepare($queryString); + foreach ($params as $key => $value) { + $type = gettype($value); + $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR); + } $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC); - $this->pdoStatement->execute($params); + $this->pdoStatement->execute(); } } catch (\PDOException $e) { $e = $this->supplementalDriver->convertException($e); diff --git a/tests/Database/ResultSet.parameters.mysql.phpt b/tests/Database/ResultSet.parameters.mysql.phpt new file mode 100644 index 000000000..46c296a51 --- /dev/null +++ b/tests/Database/ResultSet.parameters.mysql.phpt @@ -0,0 +1,18 @@ +fetch('SELECT ? AS c1, ? AS c2, ? AS c3, ? as c4', fopen(__FILE__, 'r'), TRUE, NULL, 123); + +Assert::same( + array('c1' => file_get_contents(__FILE__), 'c2' => 1, 'c3' => NULL, 'c4' => 123), + (array) $res +); diff --git a/tests/Database/ResultSet.parameters.postgre.phpt b/tests/Database/ResultSet.parameters.postgre.phpt new file mode 100644 index 000000000..afaef19f5 --- /dev/null +++ b/tests/Database/ResultSet.parameters.postgre.phpt @@ -0,0 +1,18 @@ +fetch('SELECT ? AS c1, ? AS c2, ? AS c3', TRUE, NULL, 123); + +Assert::same( + array('c1' => TRUE, 'c2' => NULL, 'c3' => 123), + (array) $res +);