This article analyzes the solution to the problem that the mysql database connection resources cannot be released in the CI framework. Share it with everyone for your reference, the details are as follows:
Query data using the classes provided by the ci framework:
$this->load->database(); $query = $this->db->query($sql);
After the program runs for a period of time, an error is reported, telling the database that there are too many connections
Obviously the MySQL database connection resources exceed the max_connections setting value. Immediately after each query, add the resource release script:
$this->db->close();
Still unable to release resources, what should I do? After checking the manual, I know, Just set pconnect to false , the settings are roughly as follows:
$db['default']['pconnect'] = FALSE;
After setting, there is no need to call
$this->db->close();
The connection will be automatically closed.
Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.