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

#1
[eluser]neen[/eluser]
I am following the below user guide page for connecting to multiple databases:

http://ellislab.com/codeigniter/user-gui...cting.html

I have the following code in my admin controller:

Code:
<?php

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


?>

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

#2
[eluser]neen[/eluser]
Nevermind, I figured it out....

#3
[eluser]browntown[/eluser]
Care to share what you did to fix this?

#4
[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-2019 MyBB Group.