Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter db->query returning false on SELECT

This particular application has been in use for over a year now, and uses several dozen models, and I am having trouble only with this one particular new function.

public function get_slides($promo = NULL) {

    $sql = "SELECT description as alt, image, link
    FROM " . CONFIG_DATABASE . ".slides
    WHERE active = '1' AND acct_no = '" . API_ACCT . "' ORDER BY priority ASC;";

    $query = $this->db->query($sql);

    var_dump($sql);
    var_dump($query);

    return $query->result_array();

}

The results of this are:

string 'SELECT description as alt, image, link
        FROM web_config_development.slides
        WHERE active = '1' AND acct_no = '10001' ORDER BY priority ASC;' (length=143)
boolean false

Followed by:

Fatal error: Call to a member function result_array() on a non-object

The query works fine in MySQL Workbench. In my searching for this issue I have come across docs referring to true/false responses on INSERT and DELETE, but not on SELECT.

This does not make any sense ... if you have any ideas, sharing them would be greatly appreciated.

like image 951
David Avatar asked Feb 22 '26 01:02

David


1 Answers

if used result_array() then first will be checked number of rows in query

if($query->num_rows()>0){
   return $query->result_array();  
}else {
   return 0; 
}
like image 115
swap Avatar answered Feb 24 '26 16:02

swap