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

4
  • 1
    How you set the production environment? What you are getting when you do echo ENVIRONMENT in index.php? Commented Sep 5, 2019 at 6:32
  • I added definition line to the code Commented Sep 5, 2019 at 8:16
  • have you checked echo ENVIRONMENT value? it should be production. Commented Sep 5, 2019 at 8:50
  • @VinayPatil It's 'production' in MY_Controller.php Commented Sep 18, 2019 at 5:28

1 Answer 1

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
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.