用于添加新数据库的 Drupal 用户界面


drupal user interface to add a new database

我正在使用drupal,我的想法是创建一个模块,为用户提供一个接口来定义新的数据库参数,因此用户界面将是一些drupal形式,用户必须提供数据库名称,用户名,密码...并提交。是否可以获取提交的值并将它们放入同一模块中的数组中,然后使用新数组连接到数据库并执行一些查询操作?

<?php
// drupal forms to fill the database parameters
// submitt the values
// insert the submitted velues into the following array:
  $other_database = array(
      'database' => databasename,
      'username' => username,
      'password' => psw,
      'host' => host,
      'port' => port,
      'driver' => drv,
      'prefix' => '',
 );
  /
  Database::addConnectionInfo(databasename, 'default', $other_database);
  db_set_active(databasename);
  // execute queries here
  db_set_active(); // without the paramater means set back to the default for the site
  drupal_set_message(t('The queries have been made.'));

签出hook_menu并形成API,这是教程页面,https://drupal.org/node/262422