I am using this class:
<?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"];
}
}
?>
And I am using auto load feature for database. My config file:
$autoload['libraries'] = array('database','session');
But you can see I am not using database in decrypt1
method. Will codeigniter connect to database even i don't use the database operation?
This is a portion of CI DB_Driver
class:
/**
* 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);
}
As you can see, database driver isn't loaded (and thus connected to db server) until the first query (DB_Driver::query()
behaves almost same).
Another point, if somewhere earlier in the code you performed some db queries (like, checking user session/activity), then connection to db server is already established, even if you don't perform any queries to db in your's decrypt1()
method.
Upd. Make sure to use lazy-loading in database config (autoinit
option should be false
).