Currently, for mysql, mysqli and pgsql, db_fetch_array and db_fetch_object all perform this test:

if ($result) { // perform fetch

It is however less correct than:

if (is_resource($result)) { // perform fetch

Testing for is_resource instead of merely existence can catch more errors, notably by avoiding the occasional error in coding where someone tries to fetch from a query string instead of fetching from the relevant query.

OTOH, if we are ready to let non-resources be passed to the underlying fetch function, as is currently the case, there is not need to test $result and the test can be removed, possibly to be replaced by a try/catch block, although since this depends on PHP5 we probably want to wait for D7 before switching to this model.

CommentFileSizeAuthor
#1 using_is_resource.patch2.67 KBmichalto

Comments

michalto’s picture

StatusFileSize
new2.67 KB

I've attached a patch for the mentioned changes.

keith.smith’s picture

Status: Active » Needs work

Minor coding style issue: there are some odd indents or tabs in the patch.

michalto’s picture

Where and what exactly?

dpearcefl’s picture

Is this still an issue in current D6?

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.