db_result documentation states that the return value for no record found is "FALSE"
It is actually "NULL"

Comments

add1sun’s picture

Project: Documentation » Drupal core
Version: » 6.x-dev
Component: Correction/Clarification » documentation

Moving to correct queue.

heine’s picture

Status: Active » Postponed (maintainer needs more info)

With the mysqli db driver:

$result = db_result(db_query("SELECT nid FROM node WHERE nid < 0"));

var_dump($result);

Results in bool(false), gettype() confirms bool.

heine’s picture

Based on a comment of Jmorahan I tried it with the mysql driver as well, still a bool on 6.x-dev

heine’s picture

The same issue was fixed in #98988: db_result should return FALSE if no result was found., long before 6.x.

dave reid’s picture

database.pgsql.inc:

function db_result($result) {
  if ($result && pg_num_rows($result) > 0) {
    $array = pg_fetch_row($result);
    return $array[0];
  }
  return FALSE;
}

database.mysql.inc:

function db_result($result) {
  if ($result && mysql_num_rows($result) > 0) {
    // The mysql_fetch_row function has an optional second parameter $row
    // but that can't be used for compatibility with Oracle, DB2, etc.
    $array = mysql_fetch_row($result);
    return $array[0];
  }
  return FALSE;
}

database.mysqli.inc:

function db_result($result) {
  if ($result && mysqli_num_rows($result) > 0) {
    // The mysqli_fetch_row function has an optional second parameter $row
    // but that can't be used for compatibility with Oracle, DB2, etc.
    $array = mysqli_fetch_row($result);
    return $array[0];
  }
  return FALSE;
}

All three return FALSE when a result is not found. If you can provide an example, we can test it, but right now it looks correct.

epimeth’s picture

Status: Postponed (maintainer needs more info) » Fixed

Seems like it was fixed on some earlier update. Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.