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();