Hi Guys

Does anybody know how to insert data into a table after the tables have been created with the drupal_install_schema().

Can this be done from mymodule.install file or will I have to created a admin section in my module to do this:

How do I incorporate this into my mymodule.install file:

insert into {folders} (folder_id, name, datecreated ) values (1, 'Data', '". date("Y-m-d g:i") ."')");

Thanks

Comments

aj045’s picture

.install files can implement the hook_install() hook. You can first do drupal_install_schema() and then fill the database. Example

function mymodule_install() {
  drupal_install_schema(/*you schema data here */);
  // now fill the database table with your schema...
  db_query(/* Query to fill db table here */);
  // add any number of db_query() calls needed to 
  // fill your table.
}
Wyze1’s picture

Thanks allot for your assistance!

In Open Source I Trust! Everybody Else Must Pay Cash!

haggins’s picture

I'm trying exactly this thing but it doesn't work by enabling a module. mymodule_install() seems only be called by the devel-module by reinstalling my module. Then all querys were executed correctly!

Any suggestions?

edit: I was blind...didn't uninstall the module so the hook_install() wasn't fired.