File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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```
8790Note that update query will return 0 in case update query will fail AND also in case
8891where no records were modified.
You can’t perform that action at this time.
0 commit comments