0

I have been using these lines of code for connecting multiple databases in codeigniter but getting error. My new db connection is for new_group.

$this->new_group = $this->CI->load->database('new_group', TRUE); 
$q = $this->new_group->query("SELECT* FROM mytable ORDER BY id DESC");

Call to a member function database() on a non-object.

Waiting for response. Thanks

2 Answers 2

2

Try this http://codeigniter.com/forums/viewthread/145901/

$db['new_group']['pconnect'] = FALSE;

I didnt try...

Sign up to request clarification or add additional context in comments.

2 Comments

You need to $second_db = $this->load->database('new_group'); first and then use $second_db->query('SQL Query'); to use it (it's recommended to use a class property to 'globalize' your second database connection - $this->second_db = ... )
I have to fetch data from 2 databases one after other so that i am using this. first declaring $this->new_group = $this->CI->load->database('new_group', TRUE); and then executing my query on db.
2

remove ->CI from the load command

$this->new_group = $this->load->database('new_group', TRUE); 
$q = $this->new_group->query("SELECT* FROM mytable ORDER BY id DESC");

or you have to load the CI object first:

$this->CI =& get_instance();
$this->new_group = $this->CI->load->database('new_group', TRUE); 
$q = $this->new_group->query("SELECT* FROM mytable ORDER BY id DESC");

1 Comment

...so if my answer worked - why did you 'accept' the other answer as correct? lol...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.