Search code examples
phpdatecodeigniter-2

codeigniter num_rows throws timezone error when corrected then page shows 500 internal server error


I am using codeigniter 2 for a module in my site. this is the first run on production.

num_rows() throws the following error

A PHP Error was encountered

Severity: Warning

Message: Home::index() [home.index]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Calcutta' for 'IST/5.0/no DST' instead

Filename: controllers/home.php

Line Number: 18

in line no 18 i have echo $catgory->num_rows();

then i updated the code as follows

function __construct()
{
    date_default_timezone_set('UTC');
    parent::__construct();
}

When reloaded the page i get

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

What could be the problem?

Is there any possibility to hide this particular error?

Is it anything to do with the server side settings?


Solution

  • The problem is not with timezone.

    I checked the logs and found that the a Fatal error has occurred and codeigniter sends 500 status to the browser.

    I did ini_set('display_errors', 1) and CI displayed the actual error instead of sending 500 status to the client.

    So at this point either turn off all errors in production or enable it to see all the initial conflicts(errors) (because development will be different in production in some cases) and then after a test drive then again hide all errors.

    I got the information while reading this post in stackoverflow

    Codeigniter displays a blank page instead of error messages

    Besides, instead of setting timezone in each controller i set it in index.php.