1

I have made a project that's join query is working in local server, but not working on live server.

Live server shows an error as

Fatal error: Call to a member function result() on a non-object in /home/a3608717/public_html/CI/application/models/student_model.php on line 157

public function fetch_all_sbj(){
    $query = $this->db->query("SELECT s.*,ct.* 
                               from subject s INNER JOIN courseTerm ct   
                                 ON s.sbjId=ct.cTId");

    return $query->result(); ///This is 157 line   
}

If I write this query as

$query = $this->db->query("SELECT * from subject ");

or

$query = $this->db->query("SELECT * from courseTerm ");

The there is no error, But I need to join them. Similary, Problem also all of the query. Please help me.

Quasdunk
  • 14,944
  • 3
  • 36
  • 45
user3617840
  • 67
  • 2
  • 10
  • there is no reason for same query to fail on live server unless its not connecting to DB via your script or connecting to a wrong DB or tables are not there in live – Abhik Chakraborty May 08 '14 at 19:08
  • If there is a db connection error ? How they work when I change the query that i prescribed before. – user3617840 May 08 '14 at 19:11
  • The error probably means that `$query` is `null` which would most likely be the case if there are no results returned by the query. Check in your DB-class if `query()` returns `null` if the result is empty. Do you have the exact same datasets in your production tables as in your local tables? – Quasdunk May 08 '14 at 19:12
  • Quasdunk, Exactly you catch. I check it using var_dump but the query empty when it is join. – user3617840 May 08 '14 at 19:16
  • The is almost certainly a difference between your production and dev databases. What happens when you run the query directly on the database using a mysql client? – Jerry May 08 '14 at 19:16
  • Ok :) So you should fix your DB-class accordingly or check if `$query` is not null before calling `result()` on it and everything should work fine again :) – Quasdunk May 08 '14 at 19:18
  • you might want to check http://stackoverflow.com/questions/7843406/codeigniter-how-to-catch-db-errors to see if there is useful error information when it fails. Also, use `$this->db->last_query()` to see if there are any surprises. – Jerry May 08 '14 at 19:22

1 Answers1

1

Fixed your database class name. It is necessary. May be you have written you model class name as

  class event_model extends CI_Model and change it
  class Event_model extends CI_Model
  also change your db collaborate in config.php