2011-12-14 22 views

回答

2

您可以使用此代码(这是相同的代码,这是在JFactory :: getDBO()方法)。

jimport('joomla.database.database'); 
jimport('joomla.database.table'); 

$conf = JFactory::getConfig(); 

$host = $conf->get('host'); 
$user = $conf->get('user'); 
$password = $conf->get('password'); 
$database = 'YOUR_DATABASE_NAME'; 
$prefix = $conf->get('dbprefix'); //***Change this if the dbprefix is not the same!*** 
$driver = $conf->get('dbtype'); 

$options = array ('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix); 

$db = JDatabase::getInstance($options); 

我希望它有帮助!

0

获取配置值如下:

$app = JFactory::getApplication();  
echo $app->getCfg('user'); 
echo $app->getCfg('password'); 
相关问题