简体   繁体   中英

Fatal Error:Call to a member function num_rows() on a non-object

As I have done codeigniter project, transferred the files from local server to live server, Here everything seems correct,

http://royal.skylabsinc.in/

Yet shows an error..Pls help me out in this... here an screen shot

" Fatal error: Call to a member function num_rows() on a non-object in /home2/skylabsi/public_html/royal/system/libraries/Session.php on line 215 "

I had the same error. You can try to create ci_session table in your database. It has resolved my problem.

/home2/skylabsi/public_html/royal/system/libraries/Session.php suggests that the problem has to do with the session.

Call to a member function num_rows() on a non-object suggests that an expected object is null, most likely caused by a bad query from the database.

I also was able to load the page when I first clicked the link, but refreshing/revisiting fails. Checked on a different browser to start a fresh session, got the same thing. First load is fine, subsequent ones aren't. This again suggests an issue with the session.

Let me guess, your localserver is windows and live server is linux. If so then most probably you have named your modal with different capitalization in the file name, class name & calling name.

Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.

The file name will be a lower case version of your class name.

add the following code to the class

private $CI;

public function __construct()
{
     $this->CI = &get_instance();
     $this->load->library('session');
     $this->load->database();
}

Very quick and short answer is:

Make sure you have ' CI_SESSION ' table on your server database if you set $this->load->library('session'); in your config/autoload.php .

CREATE TABLE IF NOT EXISTS `ci_sessions` (
  `session_id` varchar(40) NOT NULL DEFAULT '0',
  `ip_address` varchar(45) NOT NULL DEFAULT '0',
  `user_agent` varchar(120) NOT NULL,
  `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
  `user_data` text NOT NULL,
  PRIMARY KEY (`session_id`),
  KEY `last_activity_idx` (`last_activity`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

if you using CI_SESSION then must you have CI_SESSION table.

I too faced this error though CI_SESSIONS table exists in database. The solution is :

As on my live server i had created database user and database but i didn't assigned User to the Database and hence it was an permission issue and the mysql user through which i was connecting didn't had permission to read DB and hence the table CI_SESSIONS.

This one working for me

Remove this two line form your config.php

$config['sess_use_database']     = TRUE;
$config['sess_table_name']       = 'ci_sessions';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM