diff --git a/src/PdoConnection.php b/src/PdoConnection.php index 6bafd6e..a71d161 100644 --- a/src/PdoConnection.php +++ b/src/PdoConnection.php @@ -178,6 +178,7 @@ public function setAttribute($attribute, $value) public function query($sql) { $params = func_get_args(); + // Shift the SQL parameter off of the list array_shift($params); @@ -192,8 +193,18 @@ public function query($sql) // Store this statement in our PDO object for easy use later $this->statement = $this->prepare($sql, $this->fetchMode); + // Automatically detect parameters type + foreach ($params as $i => $param) { + $type = PDO::PARAM_STR; + if (is_int($param) || (is_string($param) && ctype_digit($param) && $param[0] !== '0')) { + $type = PDO::PARAM_INT; + } + + $this->statement->bindValue($i + 1, $param, $type); + } + // Execute the query - $this->statement->execute($params); + $this->statement->execute(); // Return the statement return $this->statement;