Will CI detect connection itself? |
05-17-2016, 07:23 AM
(This post was last modified: 05-17-2016, 07:24 AM by chan15. Edit Reason: typo )
There is a helper need to check something by connect to database in a loop, for example:
view PHP Code: <?php foreach ($datas as $data): ?> helper PHP Code: <?php I don't like to connect to database in construct or in autoload, I like to declare it in where need it, but I was wonder if CI smart enough to check if the connection is exists, or it will do the connection thing as much as data exists as example.
I'm not sure I completely understand what you mean by "check the existing connection" but codeigniter needs to have the database loaded beforehand.
Is there any particular reason you don't like loading the database with the framework?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
(05-17-2016, 07:43 PM)albertleao Wrote: I'm not sure I completely understand what you mean by "check the existing connection" but codeigniter needs to have the database loaded beforehand. I loading the database with the framework, I mean I don't like to load it in __construction, if I have three methods in a controller, I will load database in each of them, even connect to the same database. I supposed $this->load->model('Members') means to build a MySQL connection, so I was wonder if I call a helper with $this->load->model('Members') 10 times will do 10 times MYSQL connection, that's my question. |
Welcome Guest, Not a member yet? Register Sign In |