Drupal Database Access

Single node output: Sony use Drupal

Get many items using an object

Node:1 Title: IBM picks Drupal as the number one content management system

Node:2 Title: Us Magazine switches to Drupal

Node:3 Title: Dabble

Node:4 Title: Songbird

Node:5 Title: Fearless Living

Number of records found: 10

A node data record looks like this:

stdClass Object
(
    [nid] => 1
    [vid] => 1
    [type] => story
    [title] => IBM picks Drupal as the number one content management system
    [uid] => 1
    [status] => 1
    [created] => 1160239418
    [changed] => 1227717576
    [comment] => 2
    [promote] => 0
    [moderate] => 0
    [sticky] => 0
    [language] => 
    [tnid] => 0
    [translate] => 0
)

Get many items using an array, one row at a time

Node:1 Title: IBM picks Drupal as the number one content management system

Node:2 Title: Us Magazine switches to Drupal

Node:3 Title: Dabble

Node:4 Title: Songbird

Node:5 Title: Fearless Living

Read all or part of a table into an array

Number of records found: 2

The array looks like this:

Array
(
    [0] => Array
        (
            [nid] => 6
            [vid] => 6
            [type] => story
            [title] => Participant Productions
            [uid] => 1
            [status] => 1
            [created] => 1164637538
            [changed] => 1227717595
            [comment] => 2
            [promote] => 0
            [moderate] => 0
            [sticky] => 0
            [language] => 
            [tnid] => 0
            [translate] => 0
        )

    [1] => Array
        (
            [nid] => 7
            [vid] => 7
            [type] => story
            [title] => BuyBlue
            [uid] => 1
            [status] => 1
            [created] => 1164637627
            [changed] => 1227717590
            [comment] => 2
            [promote] => 0
            [moderate] => 0
            [sticky] => 0
            [language] => 
            [tnid] => 0
            [translate] => 0
        )

    [2] => 
)

Read all or part of a table into an array, indexed off the nid

The array now has the nid as its key and no empty entry at the end:

Array
(
    [8] => Array
        (
            [nid] => 8
            [vid] => 8
            [type] => story
            [title] => Sites by Web.net
            [uid] => 1
            [status] => 1
            [created] => 1164637798
            [changed] => 1227717600
            [comment] => 2
            [promote] => 0
            [moderate] => 0
            [sticky] => 0
            [language] => 
            [tnid] => 0
            [translate] => 0
        )

    [9] => Array
        (
            [nid] => 9
            [vid] => 9
            [type] => story
            [title] => Political websites
            [uid] => 1
            [status] => 1
            [created] => 1164637880
            [changed] => 1227717604
            [comment] => 2
            [promote] => 0
            [moderate] => 0
            [sticky] => 0
            [language] => 
            [tnid] => 0
            [translate] => 0
        )

)
The official documentation is here: http://api.drupal.org/api/group/database/6