1

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?

2

1 Answer 1

0

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.