Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9b1a282

Browse files
vincentselsdregad
authored andcommittedJun 1, 2012
Don't throw error when using db_fetch_array on empty resultset
When you execute a query which returns no results, an error is thrown when using db_fetch_array() on it, because the method tries to access the EOF property of an object which in that case is null. By adding an extra check on the passed p_result to see whether it is null, you can safely use db_fetch_array for instance in while loops, without having to always manually check whether or not the result has rows. This makes code more readable and faster. Fixes #14336 Signed-off-by: Damien Regad <damien.regad@merckgroup.com>
1 parent 1c9c8e2 commit 9b1a282

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎core/database_api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ function db_affected_rows() {
450450
function db_fetch_array( &$p_result ) {
451451
global $g_db, $g_db_type;
452452

453-
if( $p_result->EOF ) {
453+
if( is_null( $p_result ) || $p_result->EOF ) {
454454
return false;
455455
}
456456

0 commit comments

Comments
 (0)
Please sign in to comment.