Skip to content

Commit 33170d2

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 c8a0c59 commit 33170d2

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
@@ -427,7 +427,7 @@ function db_affected_rows() {
427427
function db_fetch_array( &$p_result ) {
428428
global $g_db, $g_db_type;
429429

430-
if( $p_result->EOF ) {
430+
if( is_null( $p_result ) || $p_result->EOF ) {
431431
return false;
432432
}
433433

0 commit comments

Comments
 (0)