Welcome Guest, Not a member yet? Register   Sign In
How CodeIgniter close db connections?

CI establishes the database connection when the database is loaded either through inclusion in autoload.php or by calling
PHP Code:

If that line is called more than once nothing will change. Except under special circumstances the database class is only loaded once establishing one connection. That connection will continue to be used throughout the execution of the current instance of CI. It does not matter how many models are loaded or how many database operations are performed the same connection will be used. As mentioned earlier, all open connections and result sets are automatically destroyed (closed) when a PHP script finishes executing.

Additional connections can be created, but that requires providing optional parameters to load->database(). See the documentation for details. This use is the "special circumstances" I mentioned above. I assume you are using this feature to make cross-database queries.

Your 'max_user_connections' troubles might be related to making calls to load->database() with the same parameters. In other words, if you are doing something like this within a model to use more than one db.

PHP Code:
$DB1 $this->load->database('group_one'TRUE);
$DB2 $this->load->database('group_two'TRUE); 

If you make the same calls again in a different model (or module?) that might be the source of your problem.

When the model is done with its job you should probably call
PHP Code:
to assure the connections are closed.

Maybe making the connections ($DB1, $DB2) properties of the controller so they can be utilized in any model or library loaded would be helpful. I have no knowledge on how using HMVC affects the usefulness of this idea.

Messages In This Thread
RE: How CodeIgniter close db connections? - by dave friend - 05-23-2017, 11:23 AM

Theme © iAndrew 2016 - Forum software by © MyBB