Use drupal_write_record().