From cfea81468e8973bd4eee083d3d1649ceaf30c114 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Fri, 3 Nov 2023 13:39:43 +0100 Subject: [PATCH] fix: passing empty array to where() throws --- src/MySQL.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/MySQL.php b/src/MySQL.php index 2d4a937..b88f6c3 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -72,7 +72,7 @@ } // Create a WHERE statement from filters - public function where(?array ...$conditions): self { + public function where(array ...$conditions): self { $values = []; $filters = []; @@ -80,6 +80,11 @@ foreach ($conditions as $condition) { $filter = []; + // Move along if the condition is empty + if (empty($condition)) { + continue; + } + // Create SQL string and append values to array for prepared statement foreach ($condition as $col => $value) { if ($this->model && !$this->in_model($col)) { @@ -96,6 +101,11 @@ $filters[] = "(" . implode(" AND ", $filter) . ")"; } + // Do nothing if no filters were set + if (empty($filters)) { + return $this; + } + // OR all filter groups $this->filter_sql = implode(" OR ", $filters); // Set values property