2012-06-16 54 views
0

使用下面的代碼:Drupal 7的數據庫API錯誤

db_update('nodesequence_nodes') 
    ->fields(array(
    'order' => 1, 
)) 
    ->condition('nid', 1, '=') 
    ->condition('nsid', 1, '=') 
    ->execute(); 

我得到以下錯誤:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order='1' WHERE (nid = '1') AND (nsid = '1')' at line 1: UPDATE {nodesequence_nodes} SET order=:db_update_placeholder_0 WHERE (nid = :db_condition_placeholder_0) AND (nsid = :db_condition_placeholder_1) ; Array ([:db_update_placeholder_0] => 1 [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 1 ) in nodesequence_init() (line 13 of /var/www/eventbooking2/sites/all/modules/nodesequence/nodesequence.module).

我很抱歉,我不能提供了深入瞭解,但我希望你能。

簡單db_update代碼似乎認爲它應該工作,但我不明白爲什麼它不是 - 請幫助。

數據庫模式:

 $schema['nodesequence_nodes'] = array(
     'description' => 'Relating nodesequences to their consituent nodes.', 
     'fields'  => array(
      'nsid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), 
      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), 
      'order' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 
     ), 
     'primary key' => array('nsid', 'nid'), 
    ); 
+0

看起來好像沒什麼問題。這是一個自定義表嗎?如果是這樣,你可以顯示你的表模式? –

+0

我剛剛包含數據庫模式。謝謝 – sisko

回答