Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 7 - db_insert returns with error
    primarykey
    data
    text
    <p>I try a simple insert query in <strong>Drupal 7</strong>, but it always return with error. I tried out <strong>db_insert</strong>, <strong>drupal_write_record</strong>, and <strong>db_query</strong> also, but every functions return various errors.</p> <p>I have a <strong>tabledrag_menu</strong> table:</p> <p><img src="https://i.stack.imgur.com/1Uad0.png" alt="enter image description here"></p> <p>I have an <strong>$adat</strong> array:</p> <pre><code>Array ( [name] =&gt; Overview [weight] =&gt; 0 [group] =&gt; left [checked] =&gt; 0 [tid] =&gt; 96 [nid] =&gt; 20 ) </code></pre> <p>With var_dump it looks like this:</p> <pre><code>array(6) { ["name"]=&gt; string(8) "Overview" ["weight"]=&gt; int(0) ["group"]=&gt; string(4) "left" ["checked"]=&gt; int(0) ["tid"]=&gt; int(96) ["nid"]=&gt; int(20) } </code></pre> <p>My code, which gives the error:</p> <pre><code>$id = db_insert('tabledrag_menu')-&gt;fields($adat)-&gt;execute(); </code></pre> <p>When i use the <strong>db_insert</strong>, it return with this error message:</p> <blockquote> <p>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 )</p> </blockquote> <p>I think, this part causes the error, but i don't know how to fix it: </p> <blockquote> <p>VALUES ('Overview', '0', 'left', '0', '96', '20')</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload