Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:56:05+00:00 2026-05-29T21:56:05+00:00

I am trying to edit my config/database.php within my CodeIgniter project so that I

  • 0

I am trying to edit my config/database.php within my CodeIgniter project so that I don’t have to keep changing the database information every time I push a new version to the server. To do the latter, I have created a $debug variable, shown below, which checks against the uri to see if the site is being run on my localhost machine (where I build the project before upload) or on the actual server.

Unfortunately in the database.php file, I don’t have access to the $this variable, and as I am personally new to OOP in PHP, I am not entirely sure of a way around this. Please can you tell me how I can do so?

Thanks,

Max.

Fatal error: Using $this when not in object context in application/config/database.php on line 51

$debug = strpos($this->uri->config->item('base_url'), 'localhost'); //line 51

$db['default']['hostname'] = $debug == TRUE ? 'x' : 'y';
$db['default']['username'] = $debug == TRUE ? 'x' : 'y';
$db['default']['password'] = $debug == TRUE ? 'x' : 'y';
$db['default']['database'] = $debug == TRUE ? 'x' : 'y';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:56:06+00:00Added an answer on May 29, 2026 at 9:56 pm

    You need to a get an instance of the codeigniter object –

    $CI = get_instance();
    

    For older versions of php, use =&

    Then, use $CI wherever you would normally use $this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to edit a record. I have the default route. When I
I have a relatively big SSIS package which I'm trying to edit. I basically
I'm trying to set up autoconf for my project. I have everything working properly
I'm trying to edit one of the gem's config files and I can't find
I have am trying to create some integration tests with no external database dependencies
I making an application launcher, Launcher.exe. I'm trying to have it load a config
I'm trying to test using a TimedRotatingFileHandler with a logging.config file, nothing that complicated
I have been trying to develop some user controls, one being a text edit
I'm trying to edit the output joomla main_menu module so I can make a
I'm trying to edit a textbox's text in a Page_Load form on an ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.