Connecting to second db issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Connecting to second db issue (/showthread.php?tid=10804) Pages:
1
2
|
Connecting to second db issue - El Forum - 08-13-2008 [eluser]Bramme[/eluser] Hey all. I need to connect to a second db (the phpbb db) to fetch a list of recent topics. I use this code: Code: $dsn = 'mysql://user:pass@localhost/phpbb3'; Connecting to second db issue - El Forum - 08-13-2008 [eluser]Hannes Nevalainen[/eluser] I'm not sure you can access your database with a dsn,, Setup a second connection in your config/database.php =) DB connection in user guide Happy Coding =) Connecting to second db issue - El Forum - 08-13-2008 [eluser]Bramme[/eluser] From that same page... Quote:Or you can submit your database values as a Data Source Name. DSNs must have this prototype: Connecting to second db issue - El Forum - 08-13-2008 [eluser]Hannes Nevalainen[/eluser] Srry, My bad. Try to Code: echo '<pre>',print_r($query),'</pre>'; Post the results please, (if it doesn't help ypu) Connecting to second db issue - El Forum - 08-13-2008 [eluser]Bramme[/eluser] Code: echo "query: <pre>"; Code: query: <pre></pre> Connecting to second db issue - El Forum - 08-13-2008 [eluser]Bramme[/eluser] Okay, nevermind. it's clearly a bug, because when I connect using a different group in the database config file, everything works. Connecting to second db issue - El Forum - 08-13-2008 [eluser]Hannes Nevalainen[/eluser] look at the top in sourece (the print_r()) echoes it's result, to ,make it return you have to provide the second parameter bool:TRUE). print_r($query,true); I forgot this (like always) Connecting to second db issue - El Forum - 08-13-2008 [eluser]xwero[/eluser] My guess is if you load a connection string the AR library isn't available. If that is the problem it should be mentioned somewhere in the documentation and also a way to make the AR library available working with connection strings. You could try Code: $query = $this->db->query('SELECT phpbb3_topics.* FROM phpbb3_topics JOIN phpbb3_posts ON phpbb3_posts.topic_id = phpbb3_topics.topic_id LIMIT 4'); Connecting to second db issue - El Forum - 08-13-2008 [eluser]Bramme[/eluser] Okay, this is even more annoying. I can succesfully connect to the second database. Though when I do that, even if I use mysql_close(), the database library uses the second database to do all my other queries. Offcourse I end up with an sql error then because it can't find the tables. Connecting to second db issue - El Forum - 08-13-2008 [eluser]xwero[/eluser] Have you set the pconnect setting to false? |