mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-13 16:23:42 +02:00
fix: passing empty array to where() throws (#21)
This commit is contained in:
parent
f9ec906414
commit
d9f450112e
1 changed files with 11 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue