Welcome Guest, Not a member yet? Register   Sign In
Problem using multiple database
#1

[eluser]Unknown[/eluser]
I loaded 2 database (DB1 and DB2) in 2 different model (M1 & M2) files at the start of the program.

DB1 is the default database. M1 uses DB1. I even add in the line to get the DB pointer.
$ccdbpt=$this->load->database('default',TRUE);

M2 uses DB2.
$dbpt=$this->load->database('database2',TRUE);

The controller program calls model M1 most of the time. At the middle of the program, the program calls the model M2.

The problem is that after calling model M2, the first database pointer $ccdbpt is using the 2nd database. An error is shown because the table is missing in the 2nd database.

Is this a bug or have I programmed wrongly?
#2

[eluser]Seppo[/eluser]
Are you using pconnect in both? If that's so, you have this problem:
http://www.php.net/manual/en/function.my...onnect.php
Quote:First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
#3

[eluser]Unknown[/eluser]
Thanks Seppo.

You are right. By switching off the "pconnect" in database config, the problem is solved.




Theme © iAndrew 2016 - Forum software by © MyBB