How can I insert into table a row which contains an auto incremented field? I am using drupal 7.41, I have a database table and it contains an auto incremented column/field. I am trying to insert some data into that table by using db_insert but it keeps displaying syntax error. Am I missing something in this syntax?

db_insert('my_table')
-&gt; fields(array(
    'id' =&gt; NULL, //my auto incremented field...
    'name' =&gt; $form_state['values']['name'],
    'link' =&gt; $form_state['values']['link],
    'group' =&gt; 2 /* I have already tried this field with and without integer data and string data. Eg '2' and 2*/
    )) -&gt; execute();


My mysql table contains four columns: id (Auto incremented, int), name (varchar(50)), link(varchar(200)), group (int).

I have tried every syntatic way but no to avail. And lastly here is my error message when I execute the query above:



I think there is no access violation here, since I was able to insert some other rows into different tables. Only difference is that that table has no auto incremented integer field and other integer fields. Just two varchar fields.

Thank you.
The problem is you are using the keyword GROUP as a column name. Drupal's PDO code doesn't always escape column names, so you should avoid using MySQL keywords.

See the MySQL documentation.


  Most of the reserved words in the table are forbidden by standard SQL as column or table names (for example, GROUP).