Title: Find the (potential) CI Bug
Setup:
A coder opens a custom mysql db connection within a hook. Records a record and then closes the db. Later on in the code he discovers he has issued $this->recordVisit(); again as shown. Something like this:
$this->_openDBConn();
$this->recordVisit();
$this->_closeDBConn();
:
$this->recordVisit();The problem is that the second record is written to the database even though the database connection has been closed and the connection id has been set to NULL. Both of these facts are confirmed.
The database class is manually loaded and configured properly.
Here are the basic methods:
public function recordVisit() {
$aData = array( 'remote_addr' => $_SERVER['REMOTE_ADDR']
, 'http_referer' => isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'NOT SET');
$this->oDB->insert( 'visitor', $aData );
}
protected function _openDBConn() {
require_once( BASEPATH.'database/DB'.EXT );
if( !isset( $this->oDB ) ) {
$this->oDB = DB();
}
}
protected function _closeDBConn() {
$this->oDB->close();
}Challenge: Why does the second record get written to the database after the connection has been closed?
———-
Have fun. (and yes, I know the answer)
Randy