【问题标题】:Drupal 7 : Connect & Run 2 MySQL simultaneouslyDrupal 7:同时连接并运行 2 个 MySQL
【发布时间】:2017-07-03 08:50:59
【问题描述】:

我想同时连接并运行 2 个数据库,因为我希望我的 CMS 从其他数据库中读取一些数据。有没有办法运行它?

我的设置.php

  $databases = array();
  $databases['default']['default'] = array(
      'driver' => 'mysql',
      'database' => 'portal',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost',
      'prefix' => 'drupal_',
    );

  $databases['default']['test'] = array(
      'driver' => 'mysql',
      'database2' => 'systems',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost',
      'prefix' => '',
    );

我尝试更改 drupal db sn-p 但它不起作用。未找到来自“系统”的数据。

对不起,我的英语不好。

数据库.inc

// Character set is added to dsn to ensure PDO uses the proper character
    // set when escaping. This has security implications. See
    // https://www.drupal.org/node/1201452 for further discussion.
    $dsn .= ';charset=' . $charset;
    $dsn .= ';dbname=' . $connection_options['database']['database2'];

【问题讨论】:

    标签: php mysql drupal drupal-7


    【解决方案1】:

    您将数据库数组定义为“default”中的“default”,第二个定义为“default”中的“test”。

    我使用了不同的数组结构:

    “默认”内的“默认”和 “测试”中的“默认” 这对我有用,所以尝试将第二个数据库定义更改为:

      $databases['test']['default'] = array(
    

    【讨论】:

    • 试过改变它,但它对我不起作用。另外我有两个名为门户和系统的数据库。门户网站都很好。但系统不能。我不能把这些数据库结合起来,因为这是客户的需求。
    • 我建议首先尝试仅使用系统数据库,看看这是否真的适用于您的设置?如果是这样,那么我们应该看到其他解决方案。此外,您能否提供更多详细信息,以便在代码中更改数据库连接以从系统数据库中提取数据?该代码也可能有一些故障。
    • 你在使用连接切换器 db_set_active('test');同时从系统数据库中获取数据?
    • 是的,如果我更改为“测试”数据库并显示数据,它会起作用。但是我的 cms 不会在没有“门户”数据库的情况下加载内容。 :-/.
    • 我不知道如何在 drupal 中更改数据库。所以我用这行 49 $dsn .= ';dbname=' 尝试了 database.inc 。 $connection_options['数据库']。我尝试在 Settings.php 上将其更改为“database2”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 2013-04-23
    • 2018-03-22
    • 1970-01-01
    相关资源
    最近更新 更多