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

Ask A Question

Stats

  • Questions 540k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To convert them to attributes try the following: xs.useAttributeFor(EnglishWord.class, "word");… May 17, 2026 at 2:27 am
  • Editorial Team
    Editorial Team added an answer As KiranThorat points out, addSubview retains the view, so make… May 17, 2026 at 2:27 am
  • Editorial Team
    Editorial Team added an answer I ended up changing how my entire web application works… May 17, 2026 at 2:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm writing a Drupal module that deals with creating new nodes from CSV files.
In my home directory I have a folder drupal-6.14 that contains the Drupal platform.
My dev environment is LAMP-based (Drupal); there are several JS (jQuery) files that are
Is there a SQL Server Provider for Drupal? I know that there is a
It is the first time I'm using SSL for a Drupal-based e-commerce shop. I
A have a view created with Drupal's Views module, and have given it a
What function in Drupal gets file attachment path? Edit: the attachments provided by Upload
New to php and drupal. I set up drupal and trying to customize the
what are the best security features (settings,modules) provided by drupal according to credit card
I'm writing a Drupal module and have run into what should be a trivial

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.