4.6.x database.pgsql.inc db_fetch_array($result)
4.6.x database.mysql.inc db_fetch_array($result)
4.7.x database.pgsql.inc db_fetch_array($result)
4.7.x database.mysqli.inc db_fetch_array($result)
4.7.x database.mysql.inc db_fetch_array($result)
5.x database.pgsql.inc db_fetch_array($result)
5.x database.mysqli.inc db_fetch_array($result)
5.x database.mysql.inc db_fetch_array($result)
6.x database.pgsql.inc db_fetch_array($result)
6.x database.mysqli.inc db_fetch_array($result)
6.x database.mysql.inc db_fetch_array($result)

Fetch one result row from the previous query as an array.


$result: A database query result resource, as returned from db_query().

Return value

An associative array representing the next row of the result, or FALSE. The keys of this object are the names of the table fields selected by the query, and the values are the field values for this result row.

Related topics

19 calls to db_fetch_array()
aggregator_category_load in modules/aggregator/aggregator.module
Load an aggregator category.
aggregator_feed_load in modules/aggregator/aggregator.module
Load an aggregator feed.
block_admin_configure in modules/block/block.admin.inc
Menu callback; displays the block configuration form.
block_box_get in modules/block/block.module
Returns information from database about a user-created (custom) block.
contact_load in modules/contact/contact.module
Load the data for a single contact category.

... See full list


includes/database.pgsql.inc, line 189
Database interface code for PostgreSQL database servers.


function db_fetch_array($result) {
  if ($result) {
    return pg_fetch_assoc($result);


johnennew’s picture

The PHP default function return is null. If you pass something in which causes the if statement to skip then it will return NULL and not FALSE.

Did this recently and ended up with an endless loop ....

$result = db_query(''SQL with a typo");

while (($next_record = db_fetch_array($result) !== FALSE) {
some code

tmsimont’s picture

johnnydarkko’s picture

Just providing an example...
Needed to get a list of organic groups group node id's that a user is a member of.

function MYMODULE_groups_by_user($account = NULL) {
  if (!$account) {
    global $user;
    $account = $user;
  $uid = $account->uid;
  $sql = "SELECT node.nid AS nid,";
  $sql .= " node.title AS node_title";
  $sql .= " FROM node node";
  $sql .= " LEFT JOIN og_uid og_uid ON node.nid = og_uid.nid";
  $sql .= " WHERE (node.status = 1) AND (node.type IN ('group'))";
  $sql .= " AND (og_uid.uid = %d)";
  $query = db_query($sql, $uid);
  while ($records = db_fetch_array($query)) {
    $nids[] = $records['nid'];
  return $nids;