function dbtng_example_install in Examples for Developers 8
Same name and namespace in other branches
- 7 dbtng_example/dbtng_example.install \dbtng_example_install()
- 3.x modules/dbtng_example/dbtng_example.install \dbtng_example_install()
Implements hook_install().
Creates some default entries on this module custom table.
See also
Related topics
File
- dbtng_example/
dbtng_example.install, line 17 - Install, update and uninstall functions for the dbtng_example module.
Code
function dbtng_example_install() {
// Insert some example data into our schema.
$entries = [
[
'name' => 'John',
'surname' => 'Doe',
'age' => 0,
],
[
'name' => 'John',
'surname' => 'Roe',
'age' => 100,
'uid' => 1,
],
];
$connection = \Drupal::database();
foreach ($entries as $entry) {
$connection
->insert('dbtng_example')
->fields($entry)
->execute();
}
}