Welcome Guest, Not a member yet? Register   Sign In
Multiple DB connection - System get the wrong one
#11

[eluser]xwero[/eluser]
[quote author="cinewbie81" date="1193811134"]It's already SET to True , but it doesn't working still

the following is by config/database.php

Code:
$active_group = "client";
$db['client1']['hostname'] = "localhost";
$db['client1']['username'] = "root";
$db['client1']['password'] = "password";
$db['client1']['database'] = "client1";
$db['client1']['dbdriver'] = "mysql";
$db['client1']['dbprefix'] = "";
$db['client1']['active_r'] = TRUE;
$db['client1']['pconnect'] = TRUE;
$db['client1']['db_debug'] = TRUE;
$db['client1']['cache_on'] = FALSE;
$db['client1']['cachedir'] = "";


//$active_group = "server";
$db['server']['hostname'] = "localhost";
$db['server']['username'] = "root";
$db['server']['password'] = "myserverdb";
$db['server']['dbdriver'] = "mysql";
$db['server']['dbprefix'] = "";
$db['server']['active_r'] = TRUE;
$db['server']['pconnect'] = TRUE;
$db['server']['db_debug'] = TRUE;
$db['server']['cache_on'] = FALSE;
$db['server']['cachedir'] = "";
[/quote]

The commented out part in your code
#12

[eluser]cinewbie81[/eluser]
I do as what u tell :

Code:
$active_group = "client";
$db['client1']['hostname'] = "localhost";
$db['client1']['username'] = "root";
$db['client1']['password'] = "password";
$db['client1']['database'] = "client1";
$db['client1']['dbdriver'] = "mysql";
$db['client1']['dbprefix'] = "";
$db['client1']['active_r'] = TRUE;
$db['client1']['pconnect'] = TRUE;
$db['client1']['db_debug'] = TRUE;
$db['client1']['cache_on'] = FALSE;
$db['client1']['cachedir'] = "";


//$active_group = "server";
$db['server']['hostname'] = "localhost";
$db['server']['username'] = "root";
$db['server']['password'] = "password";
$db['server']['database'] = "server";
$db['server']['dbdriver'] = "mysql";
$db['server']['dbprefix'] = "";
$db['server']['active_r'] = TRUE;
$db['server']['pconnect'] = TRUE;
$db['server']['db_debug'] = TRUE;
$db['server']['cache_on'] = FALSE;
$db['server']['cachedir'] = "";

and when the following code being executed, it give me the error "You have specified an invalid database connection group: server" .. ANy idea ??

Code:
$dbClient = $this->load->database('client', TRUE);
$dbServer = $this->load->database('server', TRUE);
#13

[eluser]xwero[/eluser]
Ok i have given you some bad advice, i'm sorry.

You have to set the pconnect key to false. I just looked how i did it with two db connections.

But you only have to define one active_group.

My code
Code:
var $db2;
    
    function Transfermodel()
    {
        parent::Model();
        $this->db2 = $this->load->database('old', TRUE);
    }
And i set the new database as active_group so in my model i could address the database objects with $this->db and $this->db2. But if you want to use it throughout your site it's better you give it clear names
#14

[eluser]cinewbie81[/eluser]
How do u set the new database as active_group ? is there any way for me to set it using the code ? or u modify it manually ?
#15

[eluser]Justin Patel[/eluser]
i also had the same problem,

but I have some temporary solutions

take a look sample below


for this do not put database library in to auto load

Code:
// FIRST DATABASE Connection  { Temporary }
    
//----------------------------------------------------------------


$dbh=mysql_pconnect ("localhost", "costa04_affiliat", "XXXXX") or die ('I cannot connect to the database because: ' . mysql_error());
            
$dbname = 'costa04_affiliate';
mysql_select_db($dbname);
$sg = mysql_query("select * from test")or die(mysql_error());
while($row = mysql_fetch_array($sg))
        echo $row['name']."<br>";
             mysql_close();


// do your work with first database

//-------------------------------------------------------------------
        
// the function need the another database connection do below code


//------------------------------------------------------------------

//-------- This is the database define in the config/database.php

            $shreeGanesh = $this->load->database();
            $this->load->model('servers_model');
            $this->load->model('proxy_model');

//------------------------------------------------------------------


I have used the both in the single function and its working great


take a try Smile
#16

[eluser]xwero[/eluser]
[quote author="cinewbie81" date="1193897949"]How do u set the new database as active_group ? is there any way for me to set it using the code ? or u modify it manually ?[/quote]

If you want your both databases loaded there is no need to change the active_group. It's just an easier way to load one of the databases.

Lets say that you have two groups : old and new and the active_group has the value old. You can set the active group to new using
Code:
$this->load->database('new');




Theme © iAndrew 2016 - Forum software by © MyBB