The issue is essentially the same as described here for db_result: http://drupal.org/node/98988

mysql, pg, sqlite, etc. functions in PHP all return FALSE if there is there is no data, but the mysqli functions return NULL.

This inconsistency makes it difficult to actually do comparisons against the return value.

see:
http://us.php.net/manual/en/function.mysqli-fetch-array.php
http://us.php.net/manual/en/function.mysql-fetch-array.php
http://us.php.net/manual/en/function.pg-fetch-object.php

chx confirmed this in the C code:

http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/mysqli.c?revision=1.106...

if (!(row = mysql_fetch_row(result))) {
RETURN_NULL();
}

Comments

chx’s picture

Status: Active » Needs review
StatusFileSize
new716 bytes
pwolanin’s picture

StatusFileSize
new58 bytes

this patch updates the doxygen comments so that it's clear that the return value for no data is expected to be FALSE. This may be important guidance if others are developing other db abstractions (e.g. sqlite, oracle, etc).

Also, I find return $return hard to parse, so this renames these variables too.

pwolanin’s picture

StatusFileSize
new4.75 KB

oops - ignore the previous file...

webernet’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good, tested OK, and it fixes some minor bugs that have shown up in the menu system.

pwolanin’s picture

this really needs to get in soon, since it's holding up testing of other patches with PHP 5.2

dries’s picture

At one point (not now), we might want to consider nuking db_fetch_array(). For core:

$ grep -r db_fetch_array * | wc -l
      60
$ grep -r db_fetch_object * | wc -l
     272

pwolanin: what other patches are you referring too?

dries’s picture

Status: Reviewed & tested by the community » Fixed

No reason not to commit this patch. Committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)