我正在使用这个类:
<?php
class Decrypt extends CI_Controller
{
public function decrypt1($toDescrypt="")
{
$this->load->library('encrypt');
$toDescrypt = urldecode($toDescrypt);
$s=unserialize($this->encrypt->decode($toDescrypt));
echo $s["username"];
}
}
?>
和我使用自动加载功能的数据库。配置文件:
$autoload['libraries'] = array('database','session');
但是你可以看到我没有在decrypt1
方法中使用数据库。将codeigniter连接到数据库,即使我不使用数据库操作?
这是DB_Driver
类的一部分:
/**
* Simple Query
* This is a simplified version of the query() function. Internally
* we only use it when running transaction commands since they do
* not require all the features of the main query() function.
*
* @access public
* @param string the sql query
* @return mixed
*/
function simple_query($sql)
{
if ( ! $this->conn_id)
{
$this->initialize();
}
return $this->_execute($sql);
}
正如你所看到的,数据库驱动程序没有加载(因此连接到数据库服务器),直到第一个查询(DB_Driver::query()
行为几乎相同)。
另一点,如果在代码的早期某个地方你执行了一些db查询(比如,检查用户会话/活动),那么连接到db服务器已经建立,即使你不执行任何查询到db在你的decrypt1()
方法。
乌利希期刊指南。确保在数据库配置中使用延迟加载(autoinit
选项应该是false
)