Problems to do a free query with codeigniter

0

I am here today to ask for help from those who are more experienced than I in the subject. I have a free query with codeigniter, which error in execution, but when I perform it in Workbenth goes right. I'll leave the code below and hope someone can help me.

protected $cms;

// Construção da classe pai
public function __construct(){  
    parent:: __construct();
    $this->cms = $this->load->database('cms', TRUE);
}

// pega os atributos para exibir no carousel
function getCarousel(){

    $this->cms->query('SELECT titulo.post_title, titulo.post_name, anexo.ID, anexo.guid 
                FROM 
                    pt_posts anexo
                inner join pt_posts titulo on titulo.ID = anexo.post_parent
                WHERE 
                    anexo.post_type = "attachment"
                ORDER BY 
                    ID 
                DESC LIMIT 4');     
    $query = $this->cms->get()->result();
    if ($query) {
        return $query;
    }else{
        return false;
    }

    
asked by anonymous 18.09.2018 / 02:08

1 answer

0

When you use the query() function of CodeIgniter, do not use get() shortly after, because query() is already a complete function. Get the result set of your query so, for example:

$this->cms->query("
    SELECT
        titulo.post_title,
        titulo.post_name,
        anexo.ID,
        anexo.guid 
    FROM 
        pt_posts anexo INNER JOIN pt_posts ON
            titulo on titulo.ID = anexo.post_parent
    WHERE 
        anexo.post_type = 'attachment'
    ORDER BY 
         ID DESC
    LIMIT 4
");    

$result_set = $query->result_array();

// Imprimindo na tela o result set
print_r($result_set);
die();
    
26.12.2018 / 18:29