【问题标题】:How to define on Drupal an external database specifying the schema如何在 Drupal 上定义指定架构的外部数据库
【发布时间】:2014-08-20 15:21:12
【问题描述】:

我想将 Drupal 连接到外部数据库,我需要指定架构,否则 Drupal 架构模块默认连接“公共”架构。我尝试了以下代码,但没有成功:

 $databases['conservation']['default'] = array(
     'database' => 'conservation',
     'schema' => 'projects_test1',
      'username' => 'xxxxxxxxxxx',
      'password' => 'xxx',
      'host' => 'xxx.xxx.xxx',
      'port' => '5432',
      'driver' => 'pgsql',
      'prefix' => array(
     'default'   => 'projects_test1.',
     'users'     => 'shared.',
     'sessions'  => 'shared.',
     'role'      => 'shared.',
     'authmap'   => 'shared.',
   )

);

我已经进行了一些谷歌搜索,但尚未发现有人尝试这样做。 谢谢 卢卡

【问题讨论】:

    标签: php drupal drupal-7 settings


    【解决方案1】:

    您可以尝试以下代码将您的 Drupal 站点连接到外部数据库:

       $databases['conservation']['default'] = array(
         'database' => 'conservation',
         'username' => 'xxxxxxxxxxx',
         'password' => 'xxx',
         'host' => 'xxx.xxx.xxx',
         'port' => '5432',
         'driver' => 'pgsql',
         'prefix' => array(
           'default'   => 'projects_test1.',
           'users'     => 'shared.',
           'sessions'  => 'shared.',
           'role'      => 'shared.',
           'authmap'   => 'shared.',
         )    
      );
    

    以上代码指定了 Drupal 的保护数据库配置。所以当你需要在你的模块中查询这个其他数据库时,你必须用这个函数切换到它的连接

    <?php
    db_set_active('your_other_db');
    ?>
    

    完成后,您必须关闭它并恢复到默认数据库连接,以便 Drupal 能够访问其数据

    <?php
    db_set_active();
    ?>
    

    【讨论】:

    • 我不想创建一个模块,但我只想使用“模式模块,以便能够使用数据表模块来可视化数据。
    • 啊!您可以尝试使用 Schema 和 Data Tables 在 drupal 7 中创建外部数据可视化视图。希望对您有所帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    相关资源
    最近更新 更多