Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

DB_driver.php, display_error method error #1862

Closed
keatliang2005 opened this Issue Oct 9, 2012 · 0 comments

Comments

Projects
None yet
2 participants

under display_error method, on line 1366

there is one tiny mistake that will cause notice error


    // --------------------------------------------------------------------

    /**
     * Display an error message
     *
     * @param   string  the error message
     * @param   string  any "swap" values
     * @param   bool    whether to localize the message
     * @return  string  sends the application/error_db.php template
     */
    public function display_error($error = '', $swap = '', $native = FALSE)
    {
        $LANG =& load_class('Lang', 'core');
        $LANG->load('db');

        $heading = $LANG->line('db_error_heading');

        if ($native === TRUE)
        {
            $message = (array) $error;
        }
        else
        {
            $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error)));
        }

        // Find the most likely culprit of the error by going through
        // the backtrace until the source file is no longer in the
        // database folder.
        $trace = debug_backtrace();
        foreach ($trace as $call)
        {
            // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes
            if (DIRECTORY_SEPARATOR !== '/')
            {
                $call['file'] = str_replace('\\', '/', $call['file']);
            }

            if (isset($call['file'], $call['class']) && strpos($call['file'], $basepath.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE) // <--- here $basepath
            {
                // Found it - use a relative path for safety
                $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']);
                $message[] = 'Line Number: '.$call['line'];
                break;
            }
        }

        $error =& load_class('Exceptions', 'core');
        echo $error->show_error($heading, $message, 'error_db');
        exit;
    }

the fix is simple just change to


if (isset($call['file'], $call['class']) && strpos($call['file'], BASEPATH.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE) // use the constant like it used to be
            {
                // Found it - use a relative path for safety
                $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']);
                $message[] = 'Line Number: '.$call['line'];
                break;
            }

narfbg added a commit that referenced this issue Oct 9, 2012

@narfbg narfbg closed this Oct 9, 2012

nonchip pushed a commit to nonchip/CodeIgniter that referenced this issue Jun 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment