function dbtng_example_install

Same name and namespace in other branches
  1. 3.x modules/dbtng_example/dbtng_example.install \dbtng_example_install()
  2. 4.0.x modules/dbtng_example/dbtng_example.install \dbtng_example_install()

Implements hook_install().

In Drupal 7, there is no need to install schema using this hook, the schema is already installed before this hook is called.

We will create a default entry in the database.

Outside of the .install file we would use drupal_write_record() to populate the database, but it cannot be used here, so we'll use db_insert().

See also

hook_install()

Related topics

File

dbtng_example/dbtng_example.install, line 22

Code

function dbtng_example_install() {
  // Add a default entry.
  $fields = array(
    'name' => 'John',
    'surname' => 'Doe',
    'age' => 0,
  );
  db_insert('dbtng_example')->fields($fields)
    ->execute();
  // Add another entry.
  $fields = array(
    'name' => 'John',
    'surname' => 'Roe',
    'age' => 100,
    'uid' => 1,
  );
  db_insert('dbtng_example')->fields($fields)
    ->execute();
}