From d2a0a6a08dd144ce95137828cb9995b3fb107b1a Mon Sep 17 00:00:00 2001 From: Abdy Franco Date: Thu, 30 Apr 2026 16:51:09 -0600 Subject: [PATCH] Enhance query method to bind parameters dynamically Automatically detect parameter types for PDO queries. --- src/PdoConnection.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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;