0

I'm using Codeigniter 3 in production mode but errors are displayed. My web server is Wampserver 3.1.7 with it's default php.ini. How can I disable error reporting?

This is part of my index.php:

    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');


    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(-1);
            ini_set('display_errors', 1);
        break;

        case 'testing':
        case 'production':
            ini_set('display_errors', 0);
            if (version_compare(PHP_VERSION, '5.3', '>='))
            {
                error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
            }
            else
            {
                error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
            }
        break;

        default:
            header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
            echo 'The application environment is not set correctly.';
            exit(1); // EXIT_ERROR
    }

And this is a part of the error I have:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>An uncaught Exception was encountered</h4>

<p>Type: Error</p>
<p>Message: Call to a member function result() on bool</p>
<p>Filename: D:\Projects\Nafis Global System\Server\application\core\MY_Model.php</p>
<p>Line Number: 377</p>


    <p>Backtrace:</p>

UPDATE:

Just some of errors are displayed. for example if the Mysqli connection did not established, this error is displayed:

Message: Call to a member function real_escape_string() on bool

rostamiani
  • 2,859
  • 7
  • 38
  • 74

1 Answers1

2

The most common place to set CI_ENV is in .htaccess using the SetEnv directive, e.g.

SetEnv CI_ENV production

it's common practice to use a different .htaccess for the development server and live server. On the development box use

SetEnv CI_ENV development

The above relates to Apache servers which must also have the env_module enabled for SetEnv to work.

NGINX or other web servers use different mechanisms to set variables.

You should also adjust the database configuration for production. In particular the item 'db_debug. The value assigned there can be set dynamically using the ENVIRONMENT variable too, e.g. in application/config/database.php

$db['default'] = array(
    //bunch of items,
    'db_debug' => ENVIRONMENT == 'development' ? true : false,
    //more items
);
DFriend
  • 8,869
  • 1
  • 13
  • 26