3

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.

6
  • I don't know how the CodeIgniter query classes work, but perhaps the ; at the end of the query string is not allowed? Aug 9, 2013 at 21:15
  • are you sure your database helper is loaded ? Aug 9, 2013 at 21:16
  • Never fails, ask the question on stack overflow, figure it out immediately. It was table permissions.
    – David
    Aug 9, 2013 at 21:18
  • 1
    Did you turn on CI's profiler $this->output->enable_profiler(TRUE); to the raw query ?
    – Dragu
    Aug 9, 2013 at 21:18
  • 1
    @David You can add that as the answer to help people having the same issue in the future.
    – joar
    Aug 9, 2013 at 21:22

3 Answers 3

1

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; 
}
0

The issue was table permissions. The application user was not added to the new table.

1
  • 2
    It seems case occurs when the query produces any type of error and db_debug is turned off. If other users have this problem, then you have an error in your query or a permission issue with the current user, something which would trigger an error. CodeIgniter simply returns false on the $this->db->get() function. Ensure db_debug is set to true in your database.php config file to have CodeIgniter display a useful error message for you.
    – AJReading
    Jun 4, 2014 at 2:24
-2

I believe you are calling the wrong method to get the result.

Try this

return $query->result();

For more information about about Codeigniter active record go here

1
  • 2
    $query->result(); gives an object. $query->result_array(); gives an associative array.
    – David
    Sep 24, 2013 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.