码迷,mamicode.com
首页 > 数据库 > 详细

drupal对数据库操作

时间:2015-05-27 18:35:11      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

// node
node_load($nid = NULL, $vid = NULL, $reset = FALSE);
node_load_multiple($nids = array(), $conditions = array(), $reset = FALSE);

// user
user_load($uid, $reset = FALSE);
user_load_multiple($uids = array(), $conditions = array(), $reset = FALSE);

// menu tree
menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL);
menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = FALSE);

// term
taxonomy_term_load($tid) : object
taxonomy_term_load_multiple($tids = array(), $conditions = array()) : array
taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE) : array

// block
block_load($module, $delta);

// Pager
db_select(‘node‘, ‘n‘)
    ->extend(‘PagerDefault‘)->limit(5)
    ->fields(‘n‘);
$statement->fetchField();
db_query_range(‘SELECT n.nid, n.title, n.created
  FROM {node} n WHERE n.uid = :uid‘, 0, 10, array(‘:uid‘ => $uid));

// insert
$fields = array(‘nid‘ => 1, ‘title‘ => ‘my title‘, ‘body‘ => ‘my body‘);
db_insert(‘node‘)->fields($fields)->execute();

// update
db_update(‘example‘)
  ->condition(‘id‘, $id)
  ->fields(array(‘field2‘ => 10))
  ->execute();

// select
$query = db_select(‘comment‘, ‘c‘)
  ->fields(‘c‘, array(‘subject‘, ‘name‘))
  ->fields(‘n‘, array(‘title‘))
  ->extend(‘PagerDefault‘)->limit(5)
  ->condition(‘n.type‘, array(‘article‘), ‘IN‘)
  ->orderBy(‘c.cid‘, ‘DESC‘);
$query->join(‘node‘, ‘n‘, ‘n.nid = c.nid‘);
$statement = $query->execute();

$query = db_select(‘node‘, ‘n‘)->fields(‘n‘, array(‘title‘))->distinct();
$query->join(‘taxonomy_index‘, ‘t‘, ‘t.nid = n.nid‘);
$or = db_or()->condition(‘n.uid‘, $authorId)->condition(‘t.tid‘, $cats, ‘IN‘);
$query->condition($or)->execute();

// fetch
foreach ($query->execute() as $object) {
  echo $object->name;
}
http://api.drupal.org/api/drupal/includes--database--database.inc/interface/DatabaseStatementInterface/7

drupal对数据库操作

标签:

原文地址:http://www.cnblogs.com/amw863/p/4533948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!