Php codeigniter中数据库的自动加载
我正在使用这个类:Php codeigniter中数据库的自动加载,php,codeigniter,Php,Codeigniter,我正在使用这个类: <?php class Decrypt extends CI_Controller { public function decrypt1($toDescrypt="") { $this->load->library('encrypt'); $toDescrypt = urldecode($toDescrypt); $s=unserialize($this->encrypt->d
<?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"];
}
}
?>
但您可以看到,我并没有在decrypt1方法中使用数据库。即使我不使用数据库操作,codeigniter还会连接到数据库吗?这是CI DB_驱动程序类的一部分:
如您所见,在第一个查询db_driver::query的行为几乎相同之前,数据库驱动程序不会被加载并因此连接到数据库服务器
另一点是,如果在代码前面的某个地方执行了一些db查询,如检查用户会话/活动,那么已经建立了到db服务器的连接,即使在decrypt1方法中没有执行任何对db的查询
Upd。确保在数据库配置autoinit选项中使用延迟加载应为false
$autoload['libraries'] = array('database','session');
/**
* 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);
}