Search code examples
drupal-7drupal-6drupal-modulesdrupal-8

undefined function db_fetch_array()


i received this error when i try to convert drupal 6 module to drupal 7.. i've learned that drupal 7 has a new api in database.. i'am hope someone can give a way to resolve this problem .

 db_set_active('data');
    $ncoa=db_fetch_array(db_query("SELECT deskripsi FROM {coa} WHERE coaid = '$baris->coa'"));
    $ukpengelola=db_fetch_array(db_query("SELECT lokasi FROM {costcenter} WHERE kodecost = '$baris->kodecost'"));
    $ukpengguna=db_fetch_array(db_query("SELECT lokasi FROM {costcenter} WHERE kodecost = '$baris->kodecostpemakai'"));
    $zstatus=db_fetch_array(db_query("SELECT status_deskripsi AS zket FROM {pengadaan_zstatus} WHERE status_id = '$baris->status_id'"));
    db_set_active('default');

Solution

  • db_fetch_array() is depreciated in D7, for a reference how to fix, see http://drupal.org/update/modules/6/7#dbtng

    Example - Drupal 6:

    <?php
    $result = db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
    ?>
    

    Drupal 7:

    <?php
    $result = db_query("SELECT * FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc();
    ?>