Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1011737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:16:46+00:00 2026-05-16T09:16:46+00:00

Drupal provides these two methods for iterating through a db_query() result. For example, $users

  • 0

Drupal provides these two methods for iterating through a db_query() result. For example,

$users = array();
$result = db_query('SELECT uid FROM {users} WHERE status=0 AND login=0');
while ($row = db_fetch_object($result)) {
    $users[] = $row->uid;
}

However, it seems that db_fetch_array($result) could be used just the same here, only with $row[‘uid’] on the next line.

What is the difference between these two methods? Are they completely interchangeable?

Source: http://api.drupal.org/api/group/database/6

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:16:46+00:00Added an answer on May 16, 2026 at 9:16 am

    The difference is that db_fetch_array() returns an array, whereas db_fetch_object() returns an object. Depending on the use-case, you might need one or the other.

    It appears, at least given the snippet you provided, they are indeed—with a change in syntax like you mentioned—interchangeable for your use-case.

    Edit

    Drupal’s db_fetch_object() and db_fetch_array() are inherited from PHP’s *_fetch_object and *_fetch_array: Drupal merely abstracts PHP’s database specific versions so a Drupal developer doesn’t have to care what database is used in the backend.

    So, the same reasons why they both exist in PHP are the same reasons why they exist in Drupal. They provide flexibility to developers: some use-cases require arrays, some require objects.

    In Drupal core, db_fetch_object() is favored far more than db_fetch_array(): you can see how each are used within core by going to each function’s API page and clicking on the header n functions call functionname.

    The reason for this bias towards db_fetch_object is mainly preference and ease of maintenance: it’s less characters to say $object->property than it is to say $object['property']. A lot of code style in Drupal is based on years of convention.

    You can use either, but think whether it makes sense, semantically, for your data to be an object or an array. For example, if you wanted to take advantage of PHP’s plethora of array functions (like array_merge(), which doesn’t have a simple object analogue), you might opt to buck convention and use db_fetch_array().

    All things being equal, *_fetch_object() is identical to *_fetch_array in terms of speed, but the resulting object from the former takes up slightly more memory than the resulting array from the latter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Drupal's UberCart is a solution, where you select some product manually and then click
I'm writing a Drupal module that deals with creating new nodes from CSV files.
I'am developing a module for Drupal which provides a login form and after submission
I have a Flash application that is hosted from within a Drupal page. Some
We are migrating a bit of an old Drupal installation (6.x) from one hosting
we develop two sites in drupal both sites have different urls and different drupal
I have a drupal website. I want to generate an Iframe with content from
Drupal has a very well-architected, jQuery -based autocomplete.js . Usually, you don't have to
Drupal employs a custom session handler that changes the familiar...: $_SESSION['foo'] = 'bar'; echo
Drupal 6 has a wonderful CSS and JavaScript aggregator. Unfortunately, it interferes with development

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.