How to programmally add nodes with next nid? i want to create multiple nodes (from csv file) the csv is loaded well, and my table node contains many old records (with nid from 1 to 170) what i want is to record the csv's new nodes with nid strating from the last one on table node (the new nodes would start from 171 on nid)
I've tried db_last_insert_id() with no success.

This is my db_merge part :

 $nodes = db_merge('node')
        -&gt;key(array('nid' =&gt; last_insert_id())) 
        -&gt;fields(array(
            'type' =&gt; 'livre',
            'uid' =&gt; 1,
            'status' =&gt; 1,
            'comment' =&gt; 1,
            'promote' =&gt; 0,
            'title' =&gt; $new_array['titre_csv']&lt;===from csv
        ))
        -&gt;execute();
Try this way:

  $node = new stdClass();
  $node-&gt;title = $new_array['titre_csv'];
  $node-&gt;type = "livre";
  node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  $node-&gt;language = LANGUAGE_NONE; // Or 'fr' in your case
  $node-&gt;uid = $user-&gt;uid; 
  $node-&gt;status = 1; //(1 or 0): published or not
  $node-&gt;promote = 0; //(1 or 0): promoted to front page
  $node-&gt;comment = 1; // 0 = comments disabled, 1 = read only, 2 = read/write
  $node = node_submit($node); // Prepare node for saving
  node_save($node);
  //save the other table


If you want to save it in your custom table you can do a db_insert or EntityFieldQuery.
In that case $node->nid value will be taken after you do the node_save (so do it after you save it with node_save).
You could also use a hook_schema for your table.