Codeigniter

时间:2018-03-07 10:30:45

标签: php mysql codeigniter

我获取了数据库信息:

$data4shop['webshops'] = $this->Product_shop_model->getWebshop($businessId)->result();

我只需要将它插入到database.php中。我希望它看起来像这样,但它不起作用:

$db['shop'] = array(
'dsn'      => '',
'hostname' => $hostname,
'username' => $username,
'password' => $password,
'database' => $database,

我不知道如何将变量传递给database.php。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

这是在控制器中:

    $db_hostname = $databaseInfo['Hostname'];
    $db_username = $databaseInfo['Username'];
    $db_password = $databaseInfo['Password'];
    $db_database = $databaseInfo['Database'];

    $config_app = switch_db_dinamico($db_hostname, $db_username, $db_password, $db_database);

    $this->Product_shop_model->shop_db = $this->load->database($config_app, TRUE);

这是帮手(db_dinamic_helper):

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function switch_db_dinamico($hostname, $username, $password, $name_db)
{
    $config_app['hostname'] = $hostname;
    $config_app['username'] = $username;
    $config_app['password'] = $password;
    $config_app['database'] = $name_db;
    $config_app['dbdriver'] = 'mysqli';
    $config_app['dbprefix'] = '';
    $config_app['pconnect'] = FALSE;
    $config_app['db_debug'] = FALSE;
    return $config_app;
}