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

nevets’s picture

See, http://drupal.org/update/modules/6/7, "A completely new database API has been added"

eabrand’s picture

Status:Active» Closed (fixed)

Thanks! Sorry about that!

drupalshrek’s picture

No 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:

<?php
    $result
= db_query('SELECT COUNT(*) AS num, DATE(FROM_UNIXTIME(access)) AS dategroup
        FROM {users}
        WHERE uid > :uid
          AND access >= :access
        GROUP BY dategroup'
, array(':uid' => 0, ':access' => $this->last_run));

    while (
$row = db_fetch_array($result)) {
     
$this->add_day_data($row['dategroup'], $row['num']);
    }
?>

becomes as follows in Drupal 7:

<?php
    $result
= db_query('SELECT COUNT(*) AS num, DATE(FROM_UNIXTIME(access)) AS dategroup
        FROM {users}
        WHERE uid > :uid
          AND access >= :access
        GROUP BY dategroup'
, array(':uid' => 0, ':access' => $this->last_run));

    foreach (
$result as $row) {
     
$this->add_day_data($row->dategroup, $row->num);
    }
?>
rahmantaufique’s picture

I 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);

rerooting’s picture

Issue summary:View changes

#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:

<?php
    $result
= db_query('SELECT COUNT(*) AS num, DATE(FROM_UNIXTIME(access)) AS dategroup
        FROM {users}
        WHERE uid > :uid
          AND access >= :access
        GROUP BY dategroup'
, array(':uid' => 0, ':access' => $this->last_run));

    foreach (
$result as $row) {
     
$row =  (array) $row;
     
$this->add_day_data($row['dategroup'], $row['num']);
    }
?>

See http://stackoverflow.com/a/4345609/1516887