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 7585265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:08:04+00:00 2026-05-30T19:08:04+00:00

How can I setup my codeigniter application so that if it cant connect to

  • 0

How can I setup my codeigniter application so that if it cant connect to one mysql server it connects to another? ie: set primary mysql and secondary mysql.

  • 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-30T19:08:05+00:00Added an answer on May 30, 2026 at 7:08 pm

    I would set up multiple codeigniter databases in the config/database (see below)

    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'uname';
    $db['default']['password'] = 'pword';
    $db['default']['database'] = '';
    $db['default']['dbdriver'] = 'mysql';
    $db['default']['dbprefix'] = '';
    $db['default']['pconnect'] = TRUE;
    $db['default']['db_debug'] = TRUE;
    $db['default']['cache_on'] = FALSE;
    $db['default']['cachedir'] = '';
    $db['default']['char_set'] = 'utf8';
    $db['default']['dbcollat'] = 'utf8_general_ci';
    $db['default']['swap_pre'] = '';
    $db['default']['autoinit'] = TRUE;
    $db['default']['stricton'] = FALSE;
    
    
    $db['db2']['hostname'] = 'hostname1';
    $db['db2']['username'] = 'uname';
    $db['db2']['password'] = 'pword';
    $db['db2']['database'] = '';
    $db['db2']['dbdriver'] = 'mysql';
    $db['db2']['dbprefix'] = '';
    $db['db2']['pconnect'] = TRUE;
    $db['db2']['db_debug'] = TRUE;
    $db['db2']['cache_on'] = FALSE;
    $db['db2']['cachedir'] = '';
    $db['db2']['char_set'] = 'utf8';
    $db['db2']['dbcollat'] = 'utf8_general_ci';
    $db['db2']['swap_pre'] = '';
    $db['db2']['autoinit'] = TRUE;
    $db['db2']['stricton'] = FALSE;
    

    Then in my controller I would load the database and check if it was successful.

     $this->db = $this->load->database('default', TRUE); //If it isn't pre-loaded 
    
        if($this->db->conn_id === FALSE){
          $this->db = $this->load->database('db2', TRUE); 
        }
    

    I haven’t tested it but I would assume it would work.

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

Sidebar

Related Questions

Can I setup Team Foundation Server in such a manner that every uer have
Can you setup a variable for javascript in one page and have another page
I can setup a connection manager that uses the Directory Services OLE provider and
I have a codeigniter multistie install where I have such code that I can
Codeigniter v2.0 that was released on the 28th. I just setup a fresh installation
I have a CodeIgniter MVC application. I have a model called city that has
I am building an application with codeigniter that involves adding a carer with multiple
Does using a PHP framework (CodeIgniter, Zend) require special server side setup? And if
My issue is i have QUERY_STRING enabled in my codeigniter setup so that links
Can I setup a custom MIME type through ASP.NET or some .NET code? I

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.