CodeIgniter Forums
Problem loading / using custom database from model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem loading / using custom database from model (/showthread.php?tid=45645)



Problem loading / using custom database from model - El Forum - 09-29-2011

[eluser]CARP[/eluser]
Hi
I'm trying to load and use an oracle database within a specific model, but I'm getting errors.

Code:
class Model_peopledata extends CI_Model {

public $DB2;

    function __construct()
    {
        parent::__construct();
    $this->$DB2 = $this->load->database("myoracle", TRUE);
    }

    function get_all_rows()
    {
        $query = $this->$DB2->get('MYTABLEORVIEW');
        return $query;
    }

}

What's wrong? I'm getting: Fatal error: Cannot access empty property in...

How should I load and use this custom database config within a model? And how should I unload this database or close the connection? Is this done automatically?

PD: Tried loading the oracle database from a controller, and works fine.

Thanks