gpt4 book ai didi

php - 如何创建连接到外部数据库的 Drupal 表单模块

转载 作者:行者123 更新时间:2023-11-29 10:48:40 25 4
gpt4 key购买 nike

Drupal 8:我想知道如何创建一个连接到外部数据库(位于 PHPMyAdmin 上)而不是 Drupal 8 数据库的表单模块。我对 Drupal 相当陌生,无法找到任何可能对我有用的示例。

非常感谢任何帮助。这个问题非常针对 Drupal 8。

最佳答案

在settings.php中

$databases = array();
$databases['default']['default'] = array(
// Drupal's default credentials here.
// This is where the Drupal core will store its data.
);
$databases['my_other_db']['default'] = array(
// Your secondary database's credentials here.
// You will be able to explicitly connect to this database from you
modules.
);

在你的模块文件中

    db_set_active('my_other_db');
// Run queries
// Change back to your DB
db_set_active();

关于php - 如何创建连接到外部数据库的 Drupal 表单模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com