• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't connect to multiple databases

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...

Nevermind, I figured it out....

Care to share what you did to fix this?

[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).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.