I should load database in my all functions?
Permalink
I should load database in my all functions?
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?
$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?
Thanks for your clarification @John
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.
Example :
public function __construct() {
$this->db = Loader::db();
}
So now you can use $this->db variable any where in class.
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.