使用ci框架提供的数据库及其类查询数据:
$this->load->database();
$query = $this->db->query($sql);
但是此时仍然没有释放资源,可以把pconnect设置为false:
$db['default']['pconnect'] = FALSE;(config文件中database.php文件)
设置过之后,无需调用 $this->db->close(); 即可自动关闭连接。
$this->load->database();
$query = $this->db->query($sql);
数据库操作完毕后,需要关闭数据库:
$this->db->close();
否则,会因为mysql数据库连接资源超过了 max_connections 设定值报错:“too many connections”。
但是此时仍然没有释放资源,可以把pconnect设置为false:
$db['default']['pconnect'] = FALSE;(config文件中database.php文件)
设置过之后,无需调用 $this->db->close(); 即可自动关闭连接。