@@ -939,6 +939,8 @@ public function update($tableName, $tableData, $numRows = null)
939
939
940
940
/**
941
941
* Delete query. Call the "where" method first.
942
+ * For better error handling, we can make use of exceptions.
943
+ * This will allow the caller to handle the error in a more specific way, including providing more specific error messages.
942
944
*
943
945
* @param string $tableName The name of the database table to work with.
944
946
* @param int|array $numRows Array to define SQL limit in format Array ($offset, $count)
@@ -950,7 +952,7 @@ public function update($tableName, $tableData, $numRows = null)
950
952
public function delete ($ tableName , $ numRows = null )
951
953
{
952
954
if ($ this ->isSubQuery ) {
953
- return ;
955
+ throw new Exception ( ' Delete function cannot be used within a subquery context. ' ) ;
954
956
}
955
957
956
958
$ table = self ::$ prefix . $ tableName ;
@@ -962,13 +964,16 @@ public function delete($tableName, $numRows = null)
962
964
}
963
965
964
966
$ stmt = $ this ->_buildQuery ($ numRows );
965
- $ stmt ->execute ();
967
+ // Error handling
968
+ if (!$ stmt ->execute ()) {
969
+ throw new Exception ('Failed to execute delete operation: ' . $ this ->_stmtError );
970
+ }
966
971
$ this ->_stmtError = $ stmt ->error ;
967
972
$ this ->_stmtErrno = $ stmt ->errno ;
968
973
$ this ->count = $ stmt ->affected_rows ;
969
974
$ this ->reset ();
970
975
971
- return ($ stmt ->affected_rows > - 1 ); // -1 indicates that the query returned an error
976
+ return ($ stmt ->affected_rows >= 0 ); // anything greater than -1 indicates success
972
977
}
973
978
974
979
/**
0 commit comments