如何在drupal中检测我正在连接的数据库类型(使用php代码)?我正在尝试编写一个模块,公开一些数据库功能,这只在postgres或sql服务器上工作。目前,我正在尝试检测数据库版本,因为每个数据库的语法似乎不同,但似乎不是很健壮。有没有一个php函数可以报告这个?
发布于 2014-02-03 21:57:00
您应该使用全局变量:$databases并检查驱动器值。
global $databases;
dpm($databases);

https://drupal.stackexchange.com/questions/48882/how-to-get-database-credentials
发布于 2014-09-19 13:53:08
我不完全明白你现在想做什么,但是
db_driver()以字符串形式返回Drupal中当前连接的数据库(例如"pgsql")。
发布于 2014-02-03 16:16:00
这可能会对你有所帮助。在执行查询之前,使用db_set_active()接口设置数据库。
这将帮助你远离错误。
<?php
//set your configurations
$db_url['default'] = 'mysql://drupal:drupal@localhost/drupal';
$db_url['mydb'] = 'mysql://user:pwd@localhost/anotherdb';
$db_url['db3'] = 'mysql://user:pwd@localhost/yetanotherdb';
//set the active database and then process your queries in this case you can always knows which database is connected now.
db_set_active('mydb');
db_query('SELECT * FROM table_in_anotherdb');设置多个数据库
<?php
// ... header of the settings.php file
$db_url = array (
"default" => "mysql://user:pass@host/db",
"second" => "pgsql://user:pass@host/db"
);
db_set_active('second');https://stackoverflow.com/questions/21522314
复制相似问题