1 dbtng_example.install dbtng_example_install()

Implements hook_install().

We will create a default entry in the database.

Outside of the .install file we would use backdrop_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

modules/examples/dbtng_example/dbtng_example.install, line 19
Install, update and uninstall functions for the dbtng_example module.

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();
}