From 9a9f473f3f3e03a826005080a554500566614415 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 16:00:29 -0500 Subject: [PATCH] - PDO Params are now properly (mostly..) binded, bool, null and int are now handled correctly --- src/Common/PdoObject.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Common/PdoObject.php b/src/Common/PdoObject.php index 15f86a2..d730c9d 100644 --- a/src/Common/PdoObject.php +++ b/src/Common/PdoObject.php @@ -29,7 +29,7 @@ class PdoObject extends PDO { return $statement; } } - catch (\PDOException $e) { + catch (\Throwable $e) { throw new \PdoException($e->getMessage() . " `$sql` with data:" . json_encode($parameters)); } } @@ -50,7 +50,7 @@ class PdoObject extends PDO { return $this->execute($statement, $parameters, true); } } - catch (\PDOException $e) { + catch (\Throwable $e) { throw new \PdoException($e->getMessage() . " `$sql` with data:" . json_encode($parameters)); } @@ -82,7 +82,27 @@ class PdoObject extends PDO { $this->beginTransaction(); } - $this->executionStatus = empty($parameters) ? $statement->execute() : $statement->execute($parameters); + foreach($parameters as $key => $value) { + switch(strtolower(gettype($value))) { + case "boolean": + $statement->bindValue($key, $value, Pdo::PARAM_BOOL); + break; + + case "integer": + $statement->bindValue($key, $value, Pdo::PARAM_INT); + break; + + case "null": + $statement->bindValue($key, $value, Pdo::PARAM_NULL); + break; + + case "string": + default: + $statement->bindValue($key, (string) $value, Pdo::PARAM_STR); + } + } + + $this->executionStatus = $statement->execute(); if ( $this->executionStatus ) { $this->lastInsertId = $this->lastInsertId();