After you have run the query and received results, you can then retrieve the actual data from the result set. There are several different methods that can be used to retrieve data from the result set including fetch
, fetchObject
, fetchAssoc
, fetchField
, fetchAll
, fetchAllAssoc
, fetchAllKeyed
, and fetchCol
. These are all called as methods on the results object. For example, the following code will return all data from the query using the default fetch
method defined in the options:
<?php $result = db_query("SELECT nid, title FROM {node}"); $all_data = $result->fetchAll(); ?>
Let's look at each fetch
method in detail now. While we review the functionality of the method, we will also match the function to the corresponding Drupal 6 functionality if applicable.