我嘗試了一個簡單的插入查詢Drupal 7,但它總是返回錯誤。 我試過了db_insert,drupal_write_record和db_query也是,但是每個函數都返回各種錯誤。Drupal 7 - db_insert返回錯誤
我有一個tabledrag_menu表:
我有一個$ ADAT陣列:
Array
(
[name] => Overview
[weight] => 0
[group] => left
[checked] => 0
[tid] => 96
[nid] => 20
)
用的var_dump它看起來像這樣:
array(6) { ["name"]=> string(8) "Overview" ["weight"]=> int(0) ["group"]=> string(4) "left" ["checked"]=> int(0) ["tid"]=> int(96) ["nid"]=> int(20) }
我的代碼,它給出了錯誤:當我使用db_insert,它與此錯誤消息返回
$id = db_insert('tabledrag_menu')->fields($adat)->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 'group, checked, tid, nid) VALUES ('Overview', '0', 'left', '0', '96', '20')' at line 1: INSERT INTO {tabledrag_menu} (name, weight, group, checked, tid, nid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5); Array ([:db_insert_placeholder_0] => Overview [:db_insert_placeholder_1] => 0 [:db_insert_placeholder_2] => left [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 96 [:db_insert_placeholder_5] => 20)
我認爲,這部分導致了錯誤,但我不知道如何修復它:
VALUES ('Overview', '0', 'left', '0', '96', '20')
是的,你說得對。謝謝。 –
僅供參考,您可以在單引號內使用'''group \'''(帶背單詞)。但如果可能,我建議更改字段名稱 – casivaagustin