Welcome Guest, Not a member yet? Register   Sign In
(solved) Database groups problems
#1

[eluser]anthrt[/eluser]
I have 2 database groups set in database.php, one is to power the website and the other is a phpBB3 forum in a seperate database.

I have the two different configurations set in database.php. In one of the models where I need to retrieve stuff from the 2nd (non default) forum DB, I tried it with

Code:
$this->load->database('forum');

But it is trying to query the default database.

I'm pretty sure it's because the database is being autoloaded. Obviously I don't want to have to manually load the database class in every controller and every method throughout the site.

Am I wrong in this assumption? If not, is there any way to overcome this problem?

Regards
#2

[eluser]rogierb[/eluser]
Did you do
Code:
$forum_db = $this->load->database('forum');
$result_object = $forum_db->query("select * from some_table");

Or did you use $this->db->query("select * from some_table")?
#3

[eluser]anthrt[/eluser]
I originally had done it the latter way you had mentioned, however i've just changed the code to this:

Code:
$forum_db = $this->load->database('forum');

$query = $forum_db->query("SELECT * FROM `phpbb_posts` WHERE `forum_id` = '24' ORDER BY `post_time` DESC LIMIT 0,$items");

return $query;

However..

Quote:Fatal error: Call to a member function query() on a non-object in /home/application/models/sitemodel.php on line 8

Regards
#4

[eluser]vitoco[/eluser]
I think that you need the second parameter TRUE , to return the db object, like this
Code:
$forum_db = $this->load->database('forum' , true );
$result_object = $forum_db->query("select * from some_table");
#5

[eluser]anthrt[/eluser]
Thanks vitoco, that's done it.




Theme © iAndrew 2016 - Forum software by © MyBB