Drupal でSQLを書く – example
Aug 13, 2015AD:
nodeテーブルからtypeをWhereに入れてSELECT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
//nidだけを知りたいだけ $results = db_select('node', 'n') ->fields('n', array('nid')) ->condition('type', 'article') ->execute() ->fetchCol(); //複数のfieldsがほしいなら $results = db_select('node', 'n') ->fields('n', array('nid', 'title')) ->condition('type', 'article') ->execute(); foreach($results as $row){ var_dump($row); } //countなら $results = db_select('node', 'n') ->fields('n', array('nid', 'title')) ->condition('type', 'article') ->execute() ->rowCount(); //queryを確認したいなら $results = db_select('node', 'n') ->fields('n', array('nid', 'title')) ->condition('type', 'article') ->execute() ->getQueryString(); |
field_data_field_package_periodテーブルから日付をWhereに入れてSELECT
1 2 3 4 5 6 |
$date = new DateTime(); $results = db_select('field_data_field_package_period', 'fpp') ->fields('fpp', array('field_package_period_value2')) ->condition('field_package_period_value2', $date->format('Y-m-d H:i:s'), '<') ->execute() ->fetchCol(); |
field_data_field_package_periodテーブルからentity_idをINでSELECT
$results = db_select('field_data_field_package_level', 'fpl')AD:
->fields('fpl', array('field_package_level_value'))
->condition('entity_id', array(1,2,3), 'IN')
->condition('field_package_level_value', 0, '!=')
->execute()
No Comments, Comment or Ping
Reply to “Drupal でSQLを書く – example”
Warning: Undefined variable $user_ID in /home/sazaeau/mizoshiri.com/public_html/blog.mizoshiri.com/wp-content/themes/grid_focus_public_mizo/comments.php on line 66
You must be logged in to post a comment.