Welcome Guest, Not a member yet? Register   Sign In
Is this a bug or just my bad practice?
#1
Question 

I think that I found a bug or just did some mess while using $this->db->select() method on my code. I'm loading all models by autoload.php, and I gave different names to all of them. But when I started to call them inside the controller, something curious happened: a portion of $this->db->select() that I used in one method of a model was interfering in the behavior of other method in another model.

Considering that the models are all loaded by autoload.php, I called its methods in my controller like this:
Code:
$arr1 = $this->model1->method1();
$arr2 = $this->model2->method2();

Then, an error message was returned:
Code:
A PHP Error was encountered
Severity: Warning
Message: pg_query(): Query failed: ERRO: column "field1" does not exist LINE 1: SELECT "field1" ^
Filename: postgre/postgre_driver.php
Line Number: 242

Here are the samples of the two methods from my models:

model1 method:
Code:
    function method1($id){
        $array = [];
        $this->db->select('field1');
        $data = ['id' => $this->db->escape_str($id)];
        $query = $this->db->get_where(self::TABLE, $data);
        foreach ($query->result_array() as $var){
            $array[] = $var['field1'];
        }
        return $array;
    }

model2 method:
Code:
    function method2($id){
        $array = [];
        $this->db->select('field2, field4');
        $data = ['id' => $this->db->escape_str($id)];
        $query = $this->db->get_where(self::TABLE, $data);
        foreach ($query->result_array() as $var){
            $array[] = $var['field2'].$var['field4'];
        }
        return $array;
    }

I've noted that removing $this->db->select('field1'), makes the things work fine.

So, it is a bug or just my bad? Huh
Reply


Messages In This Thread
Is this a bug or just my bad practice? - by BabalooAye - 07-07-2016, 08:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB