Welcome Guest, Not a member yet? Register   Sign In
Connecting to two databases simultaneously
#1

[eluser]jdav3579[/eluser]
Hi,
I have checked the docs for this answer, but can't seem to get this to work.

I have the folowing code, but in the getPage function it always attempts to use $db2 where it should be trying to use $db1.

Any help kindly appreciated!

John

class content extends Model{

var $db1;
var $db2;

function content(){
parent::Model();
$this->db1=$this->load->database('default', TRUE);
$this->db2=$this->load->database('group2', TRUE);
}



function getPage($parent, $heading){
$query=$this->engine->query("SELECT * FROM content ");
return $query->row_array();
}

}
#2

[eluser]pistolPete[/eluser]
Please use [ code ] tags!

What exactly is $this->engine ?
Did you try
Code:
$query = $this->db1->query('SELECT * FROM content');
#3

[eluser]jdav3579[/eluser]
Hi thanks for the reply.
sorry yes. The engine version was my original code. I thought I had removed all references to it when I posted!

I have tried the code you posted but to no avail!

It still tries to use the db set up in db2 though...

So very wierd.. is there any thing I need to do in the configuration to indicate that I am using 2 dbs?

Cheers
john
#4

[eluser]pistolPete[/eluser]
Do you load the database automatically?
Are you sure your database.php contains two different sets of database settings?

Do you use persistent connections?
Try:
Code:
$db['default']['pconnect'] = FALSE;
#5

[eluser]jdav3579[/eluser]
Originally I did load 1 automatically, but then figured this was possibly the problem. so loaded them manually. In your example is default one of the parameters you pass when loading the database? I am just checking, to make sure this isnt the problem.
I cant try your code till tomorrow now as the problem is in work, but I will have a look then and post a reply then. But thanks for your efforts!

John
#6

[eluser]CroNiX[/eluser]
pistolPete is referring to the database config file.
#7

[eluser]jdav3579[/eluser]
Cheers in my database config I have
Code:
$active_group="";

$db['default']['hostname']="myserver"
$db['default']['username']="myusername"
$db['default']['password']="mypass"
etc..

$db['group2']['hostname']="my_second_server"
$db['group2']['username']="my_second_username"
$db['group2']['password']="my_second_pass"
etc..
#8

[eluser]jdav3579[/eluser]
Hi,
Changing the pconnect seems to have worked.

Thanks very much for your help!




Theme © iAndrew 2016 - Forum software by © MyBB