drsxobip501258 2018-03-07 10:30
浏览 59
已采纳

Codeigniter中的动态数据库

I get the database information:

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

I only need to insert it into the database.php. I want it to look like this, but it doesn't work:

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

I don't know how to pass the variables into database.php. How can I do that?

  • 写回答

1条回答 默认 最新

  • dqellle310167 2018-03-14 13:46
    关注

    this is in the controller:

        $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);
    

    This is the helper(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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥33 集成BiLSTM模型和GCN模型时,前模型的输出不匹配后模型的输入
  • ¥15 关于液体厚度提取,和铺展轨迹数据化处理
  • ¥20 对方微信是wxid如何添加成好友?或者转换成微信号?
  • ¥15 yolov5实验数据好,但是自己拍摄的照片检测结果差
  • ¥15 做过dali2.0认证的技术,
  • ¥15 一道python难题
  • ¥15 matlab 免疫算法
  • ¥50 可视化界面构建,实现信息模块功能
  • ¥15 基于bert-base-chinese的中文文本处理
  • ¥15 高价求抖音抓包技术,抖音抓包无网络问题