From 62792e832523b0ba4a650a79b17ea4b6f27bee13 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 23:34:55 -0500 Subject: [PATCH] - Fixed a bug within INSERT query --- src/Common/PdoObject.php | 10 ++++++---- src/Query/Values.php | 5 +++-- src/Ulmus.php | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Common/PdoObject.php b/src/Common/PdoObject.php index d730c9d..a626e6a 100644 --- a/src/Common/PdoObject.php +++ b/src/Common/PdoObject.php @@ -85,21 +85,23 @@ class PdoObject extends PDO { foreach($parameters as $key => $value) { switch(strtolower(gettype($value))) { case "boolean": - $statement->bindValue($key, $value, Pdo::PARAM_BOOL); + $type = Pdo::PARAM_BOOL; break; case "integer": - $statement->bindValue($key, $value, Pdo::PARAM_INT); + $type = Pdo::PARAM_INT; break; case "null": - $statement->bindValue($key, $value, Pdo::PARAM_NULL); + $type = Pdo::PARAM_NULL; break; case "string": default: - $statement->bindValue($key, (string) $value, Pdo::PARAM_STR); + $type = Pdo::PARAM_STR; } + + $statement->bindValue($key, (string) $value, $type); } $this->executionStatus = $statement->execute(); diff --git a/src/Query/Values.php b/src/Query/Values.php index 1bd11f4..2ffc826 100644 --- a/src/Query/Values.php +++ b/src/Query/Values.php @@ -24,8 +24,9 @@ class Values extends Fragment { if ($this->fieldCount === null) { $this->fieldCount = count($row); } - - $this->rows[] = array_values($row); + + # index starts at '1' for Pdo params + $this->rows[] = array_combine(range(1, count($row)), array_values($row)); return $this; } diff --git a/src/Ulmus.php b/src/Ulmus.php index 074e5b5..1e9527a 100644 --- a/src/Ulmus.php +++ b/src/Ulmus.php @@ -84,7 +84,7 @@ abstract class Ulmus public static function runInsertQuery(Query\QueryBuilderInterface $queryBuilder, ? ConnectionAdapter $adapter = null) { - $return = static::connector($adapter)->runInsertQuery($queryBuilder->render(), array_merge($queryBuilder->values ?? [], $queryBuilder->parameters ?? [])); + $return = static::connector($adapter)->runInsertQuery($queryBuilder->render(),$queryBuilder->values ?? []); $queryBuilder->reset(); return $return;