db_result documentation error
epimeth - October 23, 2008 - 22:26
| Project: | Drupal |
| Version: | 6.x-dev |
| Component: | documentation |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
db_result documentation states that the return value for no record found is "FALSE"
It is actually "NULL"

#1
Moving to correct queue.
#2
With the mysqli db driver:
<?php
$result = db_result(db_query("SELECT nid FROM node WHERE nid < 0"));
var_dump($result);
?>
Results in
bool(false), gettype() confirms bool.#3
Based on a comment of Jmorahan I tried it with the mysql driver as well, still a bool on 6.x-dev
#4
The same issue was fixed in #98988: db_result should return FALSE if no result was found., long before 6.x.
#5
database.pgsql.inc:
<?phpfunction db_result($result) {
if ($result && pg_num_rows($result) > 0) {
$array = pg_fetch_row($result);
return $array[0];
}
return FALSE;
}
?>
database.mysql.inc:
<?phpfunction 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:
<?phpfunction 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.
#6
Seems like it was fixed on some earlier update. Thanks all!
#7
Automatically closed -- issue fixed for two weeks with no activity.