Welcome Guest, Not a member yet? Register   Sign In
$this->load->database() in every control function
#1

[eluser]gnomixa[/eluser]
Is there a way to add it at the beginning of the application once? Calling this at the beginning of every function in the control file seems like a bad habit....also, does this create a new database connection? if so, when does it get closed?

i am concerned about database optimization and don't want to create connection that just hang there.
Please enlighten the CI newbie!
#2

[eluser]pistolPete[/eluser]
Quote:Is there a way to add it at the beginning of the application once?
Just have a look at the user guide: Automatically Connecting

A database connection gets closed on script exit, but you can also force it quit, although there is no real need to do so:
Code:
$this->db->close();
#3

[eluser]fesweb[/eluser]
If you are always using the same database, you should just save your database info once in your config/database file, and then autoload the database library in your config/autoload file.

Code:
// in config/autoload
$autoload['libraries'] = array('database', 'session');
#4

[eluser]gnomixa[/eluser]
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB