Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
db_fetch_array & db_fetch_object have disappeared in the most current version of Drupal 7 in database.inc. I checked in the change logs and no reports of changes have been made. If I'm missing something please let me know what it has been replaced with or where I can find this information in the documentation.
Thanks!
Comments
Comment #1
nevets CreditAttribution: nevets commentedSee, http://drupal.org/update/modules/6/7, "A completely new database API has been added"
Comment #2
eabrand CreditAttribution: eabrand commentedThanks! Sorry about that!
Comment #3
drupalshrek CreditAttribution: drupalshrek commentedNo worries eabrand, it's a question everyone who is converting D6 code to D7 constantly has to ask!
To give an example:
In Drupal 6:
becomes as follows in Drupal 7:
Comment #4
rahmantaufique CreditAttribution: rahmantaufique commentedI am working in drupal7 and used these codes.But It is not giving data from table to browser.
Please give idea.
Thanks,
Taufique
$header = array('Firstname', 'Lastname','Email', 'Age');
$rows = array();
$sql = 'SELECT firstname, lastname, email, age FROM {customer} ORDER BY firstname';
$res = db_query($sql);
foreach ($res as $row){
$rows[] = $row;
}
print theme('table', $header, $rows);
Comment #5
rerooting CreditAttribution: rerooting commented#3 worked for me, but here is a quick fix if you are porting code that expects $row to be an array (rather than an object), and you don't feel like going through and refactoring the code to treat $row as an object:
See http://stackoverflow.com/a/4345609/1516887
Comment #6
Chetna_Negi CreditAttribution: Chetna_Negi commentedUpgrading a Drupal 6 custom module to Drupal 7.
foreach loop is the alterative for db_fetch_array/db_fetch_object .
Comment #7
Michael-IDA CreditAttribution: Michael-IDA at Internet Design Alliance commentedThis change was fairly annoying, as it messed up elegant solutions:
Replace with:
Posting so I can find it again...