indexingdrupaldrupal-nodes

Recipe for adding Drupal node records


I am looking for a recipe for adding Drupal node records. I have identified three tables.

node_revisions
nid=249  - vid + 1?
vid=248  - auto-increment

node:
nid=250  - vid + 1?
vid=249  - auto-increment

content_type_my_content
vid=248  - from node_revisions table?
nid=249  - from node table? 

Am I on right track? Is there some helper functions for this?


Solution

  • If you are looking to programatically create nodes, use the Drupal API.

    Start by creating a $node object. Fill in title, type, status, body, plus any CCK fields. At the end, call node_save($node);.

    node_save will save your node object and do the necessary database work.

    Check this out:

    http://api.drupal.org/api/function/node_save/6

    http://mediumexposure.com/how-build-node-drupal-programmatically/

    The easiest way to see what each type of content type has as fields is to create a node (for example, Page), then use var_dump() to see the node's contents. That will show you every field you will need to use in your node object creation script.

    Some folks will say you should create a form array, and call drupal_execute() on it so validation is performed before it's saved to the database. Either way is fine.