Welcome Guest, Not a member yet? Register   Sign In
Codeigniter ignoring $this->db->close() ?

Hi There,

I'm having trouble with a database connection persisting even thou i call $this->db->close();

Below is my code

$beach_name = $this->Slsa_model->getBeachName($this->uri->segment(3));
    $data = array(
    'beach_key' => $this->uri->segment(3),
    'assessment_key' => $this->uri->segment(4),
    'name' => $beach_name

        $this->db->insert('beach', $data);


function getBeachName($beach_key)
         $sql = "SELECT * FROM beaches WHERE beach_key = ? ";
         $query = $this->db->query($sql, $beach_key);
        $row = $query->row_array();

        return $row[beach_name];

Now the issue is, when I try to perform the INSERT into POSTGRES database, i get the error message saying

ERROR: relation "beach" does not exist at character 13

After a bit of scratching around, it seems the insert is trying to apply to the ABSAMP database, not the POSTGRES

Why would this connection be persisting even thou I have closed the DB connection?

IIRC it's because of the way CI handles loading. Even if the database is closed, the $this->database variable isn't unset, so the database isn't reloaded, even though you specify a different one. You should be able to get around it with:

$this->db = $this->load->database('absamp', TRUE);

Although, because they're separate databases I would probably separate them.

$this->_db = $this->load->database('absamp', TRUE);

Thanks for the quick reply, your fix resolved the issue perfectly.

So, does this count as a bug?

Probably not... There's no clean way to "unload" anything in CI.

Theme © iAndrew 2016 - Forum software by © MyBB