Skip to content

Commit d3455fa

Browse files
Update Database.php
Merge array of $data and $where in update will result in omitted data if $data and $where fields have the same columns. Updated to append all passed values, so same columns in $data and $where will now use both values.
1 parent 1a64311 commit d3455fa

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/Database.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,28 @@ public function insert($table, $data)
193193
*/
194194
public function update($table, $data, $where)
195195
{
196-
//merge data and where together
197-
$collection = array_merge($data, $where);
198-
199-
//collect the values from collection
200-
$values = array_values($collection);
201-
196+
//collect the values from data and where
197+
$values = [];
198+
202199
//setup fields
203200
$fieldDetails = null;
204201
foreach ($data as $key => $value) {
205202
$fieldDetails .= "$key = ?,";
203+
$values[] = $value;
206204
}
207205
$fieldDetails = rtrim($fieldDetails, ',');
208-
206+
209207
//setup where
210208
$whereDetails = null;
211209
$i = 0;
212210
foreach ($where as $key => $value) {
213211
$whereDetails .= $i == 0 ? "$key = ?" : " AND $key = ?";
212+
$values[] = $value;
214213
$i++;
215214
}
216-
215+
217216
$stmt = $this->run("UPDATE $table SET $fieldDetails WHERE $whereDetails", $values);
218-
217+
219218
return $stmt->rowCount();
220219
}
221220

0 commit comments

Comments
 (0)