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
Description

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

#1

add1sun - October 23, 2008 - 22:56
Project:Documentation» Drupal
Version:<none>» 6.x-dev
Component:Correction/Clarification» documentation

Moving to correct queue.

#2

Heine - December 10, 2008 - 21:53
Status:active» postponed (maintainer needs more info)

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

Heine - December 11, 2008 - 17:01

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

#4

Heine - December 11, 2008 - 17:06

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

#5

Dave Reid - December 11, 2008 - 17:07

database.pgsql.inc:

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

database.mysql.inc:

<?php
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:

<?php
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.

#6

epimeth - December 11, 2008 - 17:12
Status:postponed (maintainer needs more info)» fixed

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

#7

System Message - December 25, 2008 - 17:21
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.