Luga
Luga

Reputation: 121

codeigniter - this->db->get() returns empty result

I have a problem regarding codeigniters db->get(). I have functioning sql query, when i pass it to db "manually", i get result, but when i use codeigniter, i get empty result. Almost same query but with like instead of where works.

The SQL is:

SELECT se.Id, se.Name, se.Alias, sy.Name as System, os.Name as Os, ac.Name as Access, se.Description
FROM cdl_server se
INNER JOIN cdl_system sy on sy.Id = se.System
INNER JOIN cdl_os os on os.Id = se.Os
INNER JOIN cdl_access ac on ac.Id = se.Access
WHERE se.Id = 1

The code looks like this:

    $this->db->select(
            'se.Id, se.Name, se.Alias, ' . 
            'sy.Name as System, os.Name as Os, ac.Name as Access, ' . 
            'se.Description', 
            FALSE);
    $this->db->from('cdl_server se');
    $this->db->join('cdl_system sy', 'sy.Id = se.System' ,'inner', FALSE);
    $this->db->join('cdl_os os', 'os.Id = se.Os' ,'inner', FALSE);
    $this->db->join('cdl_access ac', 'ac.Id = se.Access' ,'inner', FALSE);
    $this->db->where('se.Id', $id, FALSE);
    $this->db->get();

edit: I use it like: $query = $this->db->get(); return $query->result();

When i var_dump the sql query before it is sent to the database, i get this:

string(264) "SELECT se.Id, se.Name, se.Alias, sy.Name as System, os.Name as Os, ac.Name as Access, se.Description FROM cdl_server se INNER JOIN cdl_system sy ON sy.Id = se.System INNER JOIN cdl_os os ON os.Id = se.Os INNER JOIN cdl_access ac ON ac.Id = se.Access WHERE se.Id =1" 

But result is always empty, even though when i copy the above and try asking db directly, i get result i need.

Does anyone know what could be causing it?

Upvotes: 0

Views: 7676

Answers (1)

Ts8060
Ts8060

Reputation: 1070

If u want to get result you must use row() or result() function.

$this->db->get()->result();

Upvotes: 4

Related Questions