Welcome Guest, Not a member yet? Register   Sign In
$this->db and $this->dbutil point to different databases
#1

[eluser]goFrendiAsgard[/eluser]
I have a trouble with dbutil and db. Below is my code (a constructor of my model):
Code:
public function __construct(){
    // I save my database configuration in CI session
    $this->load->library('session');
    $config = $this->session->userdata("db_config");
    if($config){ // $config is now equal contains of my database configuration
        $this->db = $this->load->database($config, TRUE);
    }else{
        $this->db = $this->load->database();
    }      
    $this->load->dbutil();
    echo '<pre>'.print_r($this->db, TRUE).'</pre>';
    echo '<pre>'.print_r($this->dbutil, TRUE).'</pre>';
}
I found that $this->db and $this->dbutil point to different databases.

$this->db point to database config from session:
Code:
....
[username] => root
[password] => toor
[hostname] => localhost
[database] => coba
....
While $this->dbutil point to database config from my configuration file (application/config/database.php):
Code:
....
[username] => root
[password] => toor
[hostname] => localhost
[database] => module_devel
....
This is not expected, since I expect both of $this->db and $this->dbutil point to the same database

I've also check PHP: CodeIgniter; Managing two db connections; variable database parameters. But, for me the solution doesn't work at all.

So, anyone can discover what's wrong here? Thanks in advance
#2

[eluser]Unknown[/eluser]
this is big bug
#3

[eluser]goFrendiAsgard[/eluser]
I end up using
Code:
$query = $this->db->query("SHOW CREATE TABLE `$table_name`");
to produce create table syntax.
#4

[eluser]toopay[/eluser]
Just from quick glance, i think you are trying to dynamically changes the DB object, without notice what DB connection was used at a time. Try add reference ($this->db =&) everytime you plan to changes the DB object.
#5

[eluser]goFrendiAsgard[/eluser]
[quote author="toopay" date="1346093214"]Just from quick glance, i think you are trying to dynamically changes the DB object, without notice what DB connection was used at a time. Try add reference ($this->db =&) everytime you plan to changes the DB object.[/quote]

Thank you. Next time when I should deal with dbutil and different databases again, I'll consider it Smile




Theme © iAndrew 2016 - Forum software by © MyBB