1

As per my knowledge, if I connect MySQL, I have to close the connection immediately after executing the script otherwise it will stay opened.

My question is does codeigniter close the MySQL connection each time after executing the script? If not, how do I perform it ?

2
  • $this->db->close(); very simple Commented Jun 1, 2016 at 8:42
  • make sure persistent connection is set to false in config file $db['default']['pconnect'] = FALSE;. Default value is true. Commented Jun 1, 2016 at 8:43

3 Answers 3

1

Yes Codeigniter close connection automatically as said in manual http://www.codeigniter.com/user_guide/database/connecting.html#manually-closing-the-connection

But if you want to close explicitly you can

$this->db->close();
Sign up to request clarification or add additional context in comments.

Comments

1

Codeigniter closes its database connection. But to manually do that within your class you can use the following

$this->db->close();

Read here for more information https://www.codeigniter.com/user_guide/database/connecting.html

Comments

0

It should do yes. But its good practice to close it any way.

$connect->close();

$connect being:

$connect = new mysqli($servername, $username, $password, $dbname);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.