Skip to content

Commit 94fea95

Browse files
committed
bug #129: Check correct execution status instead of affected rows,
1 parent fe6728f commit 94fea95

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

MysqliDb.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,16 @@ public function update($tableName, $tableData)
316316

317317
$this->_query = "UPDATE " . self::$_prefix . $tableName ." SET ";
318318

319-
$stmt = $this->_buildQuery(null, $tableData);
319+
$stmt = $this->_buildQuery (null, $tableData);
320320
if ($stmt->execute() == false) {
321321
$this->reset();
322322
$this->_stmtError = $stmt->error;
323-
return -1;
323+
return false;
324324
}
325325
$this->reset();
326+
$this->count = $stmt->affected_rows;
326327

327-
return ($stmt->affected_rows > 0);
328+
return true;
328329
}
329330

330331
/**

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ $data = Array(
6868
$id = $db->insert ('users', $data);
6969
if ($id)
7070
echo 'user was created. Id=' . $id;
71+
else
72+
echo 'insert failed: ' . $db->getLastError();
73+
7174
```
7275

7376
### Update Query
@@ -81,14 +84,11 @@ $data = Array (
8184
// active = !active;
8285
);
8386
$db->where ('id', 1);
84-
$cols = $db->update ('users', $data);
85-
if ($cols == -1)
86-
echo 'update failed: ' . $db->getLastError();
87+
if ($db->update ('users', $data))
88+
echo $db->count . ' records were updated';
8789
else
88-
echo $cols . ' records were updated';
90+
echo 'update failed: ' . $db->getLastError();
8991
```
90-
Note that update query will return 0 in case update query will fail AND also in case
91-
where no records were modified.
9292

9393
### Select Query
9494
After any select/get function calls amount or returned rows

0 commit comments

Comments
 (0)