function drush_db_result

8.0.x dbtng.inc drush_db_result($result)
6.x dbtng.inc drush_db_result($result)
7.x dbtng.inc drush_db_result($result)
3.x drush.inc drush_db_result($result)
4.x drush.inc drush_db_result($result)
5.x dbtng.inc drush_db_result($result)
master dbtng.inc drush_db_result($result)

A db_result() that works consistently for any version of Drupal.

Parameters

A Database result object.:

2 calls to drush_db_result()
drush_variable_delete in commands/core/variable.drush.inc
Command callback. Delete a variable.
drush_variable_set in commands/core/variable.drush.inc
Command callback. Set a variable.

File

includes/drush.inc, line 399
The drush API implementation and helpers.

Code

function drush_db_result($result) {
  switch (drush_drupal_major_version()) {
    case 5:
      // In versions of Drupal <= 5, db_result only returns the first row no matter how
      //  many times you call it. So instead of calling it here, we use db_fetch_array which
      //  does increment the pointer to the next row (as db_result does on Drupal 6)
      if ($array = db_fetch_array($result)) {
        return array_shift($array); // return first element in array.
      }
    case 6:
      return db_result($result);
    case 7:
    default:
      return $result->fetchField();
  }
}