drupal 数据库查询的两种方式 奇

    $select = db_select('node', 'n')
               ->condition('n.type','product')
               ->fields('n', array('nid', 'title', 'created'))
               ->execute();
    foreach($select as $row){
        dpm($row);
    }

 或者

    $select = db_select('node', 'n')
        ->condition('n.type','product_sell_quote')
        ->fields('n', array('nid', 'title', 'created'))
        ->execute()
        ->fetchAllAssoc('nid');
    foreach($select as $row){
        dpm($row);
    }

 都是可以的 ...

-- 还有一个备注:
db_select确定表格
fields确定字段
condition确定条件
然后触发execute

posted @ 2015-08-12 11:06  qqisnow2021  阅读(372)  评论(0编辑  收藏  举报