Skip to content

Commit fe6728f

Browse files
committed
update () should return -1 in case if failed
1 parent 8f15313 commit fe6728f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

MysqliDb.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ public function update($tableName, $tableData)
317317
$this->_query = "UPDATE " . self::$_prefix . $tableName ." SET ";
318318

319319
$stmt = $this->_buildQuery(null, $tableData);
320-
$stmt->execute();
321-
$this->_stmtError = $stmt->error;
320+
if ($stmt->execute() == false) {
321+
$this->reset();
322+
$this->_stmtError = $stmt->error;
323+
return -1;
324+
}
322325
$this->reset();
323326

324327
return ($stmt->affected_rows > 0);
@@ -741,7 +744,6 @@ protected function _dynamicBindResults(mysqli_stmt $stmt)
741744
// https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119
742745
if (version_compare (phpversion(), '5.4', '<'))
743746
$stmt->store_result();
744-
}
745747

746748
call_user_func_array(array($stmt, 'bind_result'), $parameters);
747749

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ $data = Array (
8282
);
8383
$db->where ('id', 1);
8484
$cols = $db->update ('users', $data);
85-
echo $cols . ' records were updated';
85+
if ($cols == -1)
86+
echo 'update failed: ' . $db->getLastError();
87+
else
88+
echo $cols . ' records were updated';
8689
```
8790
Note that update query will return 0 in case update query will fail AND also in case
8891
where no records were modified.

0 commit comments

Comments
 (0)