How to access database table with drupal 7 I am quite new to Drupal. I am creating custom module which connects to the database table. I have gone through the API documentation and created a test function and tried db connect, but there seems to be an error. This is my code:

function first_db_insert() {
  db_insert('imports')
    -&gt;fields(array(
      'name' =&gt; 'Groucho',
      'address' =&gt; '123 Casablanca Ave.',
      'phone' =&gt; '555-1212',
    )
    )
  -&gt;execute();
  drupal_set_message('database updated');
}
If you have an autoincrement value for the primary key on the table you are inserting, then the execute() function will return you this increment value. So just check what it is returning.
But do make sure the value is defined as an autoincrement (defined as serial in hook_schema) because otherwise the returned value should not be used as it is undefined.

$nid = db_insert('node')
  -&gt;fields(array(
    'title' =&gt; 'This is only a test.',
    'uid' =&gt; 1,
    'created' =&gt; time(),
  ))
  -&gt;execute();
// This will ouput the $nid value to Drupal log.
 watchdog('yourmodule', "The value for nid is $nid .");