From 0235610bfabeb15348a5e8e283b2cb07bceac693 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Tue, 26 Dec 2023 12:33:38 +0100 Subject: [PATCH] fix: array type coercion for params in driver (#24) --- src/DatabaseDriver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DatabaseDriver.php b/src/DatabaseDriver.php index 111c212..7e8a366 100644 --- a/src/DatabaseDriver.php +++ b/src/DatabaseDriver.php @@ -13,9 +13,14 @@ parent::__construct(...func_get_args()); } + // Coerce input to array + private static function to_array(mixed $input): array { + return is_array($input) ? $input : [$input]; + } + // Execute SQL query with optional prepared statement and return array of affected rows public function exec(string $sql, mixed $params = null): array { - $query = $this->execute_query($sql, $params); + $query = $this->execute_query($sql, self::to_array($params)); $res = []; // Fetch rows into sequential array @@ -28,7 +33,7 @@ // Execute SQL query with optional prepared statement and return true if query was successful public function exec_bool(string $sql, mixed $params = null): bool { - $query = $this->execute_query($sql, $params); + $query = $this->execute_query($sql, self::to_array($params)); return gettype($query) === "boolean" // Type is already a bool, so return it as is