Drupal 8รุ่นของแฟ้ม .install * รหัสให้โดย @ ЕлинЙ .:
หมายเหตุ: ฐานข้อมูลต้องมีอยู่และระบุไว้ใน settings.php
<?php
function mymodule_schema_otherdb() {
$schema['mytable'] = array(
'description' => 'My table description',
'fields' => array(
'myfield' => array(
'description' => 'My field description',
'type' => 'serial',
'size' => 'medium',
'not null' => TRUE,
'unsigned' => TRUE,
),
),
'primary key' => array('myfield'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function mymodule_install() {
\Drupal\Core\Database\Database::setActiveConnection('otherdb');
$connection = \Drupal\Core\Database\Database::getConnection();
$schema = mymodule_schema_shared();
foreach ($schema as $name => $table) {
$connection->schema()->createTable($name, $table);
}
\Drupal\Core\Database\Database::setActiveConnection();
}
/**
* Implements hook_uninstall().
*/
function mymodule_uninstall() {
\Drupal\Core\Database\Database::setActiveConnection('otherdb');
$connection = \Drupal\Core\Database\Database::getConnection();
$schema = mymodule_schema_shared();
foreach ($schema as $name => $table) {
$connection->schema()->dropTable($name);
}
\Drupal\Core\Database\Database::setActiveConnection();
}
นี่คือสรุปสาระสำคัญ