CodeIgniter Forums

Full Version: Can't connect to multiple databases
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I am following the below user guide page for connecting to multiple databases:

I have the following code in my admin controller:


    class admin extends Controller {
        function __construct()
            $agilevoice = $this->load->database('agilevoice', TRUE);
            $eyebeam = $this->load->database('eyebeam', TRUE);
        function index()


And I get the following error

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: agilevoice

Filename: controllers/admin.php

Line Number: 15

Fatal error: Call to a member function get() on a non-object in /Volumes/Storage/Projects/ispcalling/system/application/controllers/admin.php on line 15

Any ideas? I am 100% sure my database.php file is correct...

El Forum

Nevermind, I figured it out....

El Forum

Care to share what you did to fix this?

El Forum

[eluser]Colin Williams[/eluser]
In class methods and functions in general, when you define a variable inside the method/function, it is only available inside the method/function. So, just because you defined the variable in the constructor doesn't mean it's available later in index(). With classes, you can share variables between methods by defining them as properties (like $this->eyebeam, $this->agilevoice).