web-dev-qa-db-ja.com

Drupal dbクエリ

このSQLクエリがあります

"SELECT url_alias.alias FROM url_alias, taxonomy_index WHERE url_alias.source = CONCAT('taxonomy/term/',taxonomy_index.tid) AND taxonomy_index.nid = 6"

drupalモジュールで実行する必要があります。どのように実行しますか?

2
Ruslan Savenok


$results = db_query("SELECT url_alias.alias FROM {url_alias}, {taxonomy_index} WHERE url_alias.source = CONCAT('taxonomy/term/',taxonomy_index.tid) AND taxonomy_index.nid = :nid", array(':nid' => 6));

foreach ($results as $result) {
  // Whatever you want to do with results
}


1
hpn

db_select:

$query = db_select('learning', 'n') 
    ->fields('n') 
    ->execute(); 
  $rows = array(); 
  while($data = $query->fetchObject()){ 
    // Fill the table rows 
    $rows[] = array( 
      $data->name, 
      $data->email, 
      $data->age, 
      $data->gender, 
      $data->about 
    ); 

db_insert:

function survey_form_submit($form, $form_state) { 
  // Here u can insert Your custom form values into your custom table. 
  db_insert('learning') 
    ->fields(array( 
      'name' => $form_state['values']['name'], 
      'email' => $form_state['values']['email'], 
      'age' => $form_state['values']['age'], 
      'gender' => $form_state['values']['gender'], 
      'about' => $form_state['values']['about'],       
    ))->execute(); 
    drupal_set_message("successfully saved survey details."); 
    drupal_goto('admin/people/survey'); 
}
0
Sam Sterlin S