I should load database in my all functions?

Permalink
I should load database in my all functions?
$db->Loader::db();

If I am using 5 functions in my model. In each functions I do some database operations like, insert, update, select.

In that case I should load database in my each function?

cjramki
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
Yes.

If its not already available, then failing to load it will result in a failed page.

If it is already available, loading it again won't hurt.
cjramki replied on at Permalink Reply
cjramki
Thanks for your clarification @John
anshul989 replied on at Permalink Reply
anshul989
You can load it in every function or there is other option. You can make constructer of class and do this thing in constructer so you have not to write this in every function.

Example :

public function __construct() {
$this->db = Loader::db();
}

So now you can use $this->db variable any where in class.