New to CI - db object issue |
[eluser]Unknown[/eluser]
Hello everyone, I'm working on a codeigniter project and there is a bug that i don't know how to resolve... The error is : Code: A Database Error Occurred On that project, i'm using 2 databases. the table 'adm_one' is a part of the 'cocco' database and not 'vocabulary' (that's why i get the error) Here is the config file : Code: $active_group = "cocco"; I autoload the 'database' library. As i understood, '$this->db' will use the 'cocco' config. To use the second database (aka vocabulary), i load it in the constructor of the model class when i need it, as followed : Code: <?php The function which create that error, is a part of the gonu_model class : Code: function get_all_cat1() { As you can see, i'm using $this->db and not $this->dbVoc. I don't know why it's trying to use 'vocabulary' settings instead of 'cocco'. When i var_dump() $this->db, i can see that "$this->db->database" is equal to cocco (which is right, and should work !) I don't know why i get this error, nor how i can debug it. If you have any advices which could help me, please share : D Thanks, Pierre (and sorry for my 'French' )
[eluser]Bart Mebane[/eluser]
According to the User Guide, under Connecting to Multiple Databases, you need to use a specific object name for each database. If you do it this way, it should work: Code: $this->dbVoc = $this->load->database('vocabulary', TRUE);
[eluser]tonanbarbarian[/eluser]
actually the easiest way to handle this is with permissions in mysql if the user account that you access the cocco database is given permission to access the vocabulary database as well then you can query the vocabulary database any time by prefixing the table name Code: SELECT * FROM (vocabulary.`adm_one`) WHERE `category` = 1 |
Welcome Guest, Not a member yet? Register Sign In |