Skip to content

Commit

Permalink
Don't throw error when using db_fetch_array on empty resultset
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vincentsels authored and dregad committed Jun 1, 2012
1 parent c8a0c59 commit 33170d2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/database_api.php
Expand Up @@ -427,7 +427,7 @@ function db_affected_rows() {
function db_fetch_array( &$p_result ) {
global $g_db, $g_db_type;

if( $p_result->EOF ) {
if( is_null( $p_result ) || $p_result->EOF ) {
return false;
}

Expand Down

0 comments on commit 33170d2

Please sign in to comment.