code Igniter Failover Array

139
April 10, 2018, at 09:06 AM

I'm not needing help with failover connection, just what might be wrong with this failover array? I have tested the alternate db connection and works great. Issue is when I turn off primary, failover does not connect as it should. This is straight from Code Igniter Documentation. So any tricks or tips to help troubleshoot?

/*
 * Mysql Driver
*/
$db['mysql']['hostname'] = getenv('DB_HOST');
$db['mysql']['username'] = getenv('DB_USERNAME');
$db['mysql']['password'] = getenv('DB_PASSWORD');
$db['mysql']['database'] = getenv('DB_DATABASE');
$db['mysql']['dbdriver'] = 'mysql';
$db['mysql']['dbprefix'] = '';
$db['mysql']['pconnect'] = FALSE;
$db['mysql']['db_debug'] = FALSE;
$db['mysql']['cache_on'] = FALSE;
$db['mysql']['cachedir'] = '';
$db['mysql']['char_set'] = 'utf8';
$db['mysql']['dbcollat'] = 'utf8_general_ci';
$db['mysql']['swap_pre'] = '';
$db['mysql']['autoinit'] = TRUE;
$db['mysql']['stricton'] = FALSE;
$db['mysql']['failover'] = array(
    array(
    'hostname' => getenv('DB_HOST2'),
    'username' => getenv('DB_USERNAME2'),
    'password' => getenv('DB_PASSWORD2'),
    'database' => getenv('DB_DATABASE2'),
    'dbdriver' => 'mysql',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE
  )
);
Answer 1

You have to set default connection try something like this :

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    .............
);
$db['default']['failover'] = array(
            array(
                    'hostname' => 'localhost1',
                    'username' => ''
                    ..........
            ),
            array(
                    'hostname' => 'localhost2',
                    'username' => ''
                    ..........
            )
);

https://codeigniter.com/user_guide/database/configuration.html

Rent Charter Buses Company
READ ALSO
Setting php generated html table in parts side by side

Setting php generated html table in parts side by side

I made this code to extract data from mysql and bring the results on the pageThe results that the code generated goes down the page

164
Possible to do a MySQL foreign key to one of two possible tables?

Possible to do a MySQL foreign key to one of two possible tables?

Well here's my problem I have three tables; regions, countries, statesCountries can be inside of regions, states can be inside of regions

134
Delete a row after 1 month or 3 month based on selected validity

Delete a row after 1 month or 3 month based on selected validity

I want to delete old records in my database that stores an entry from an HTML form which consists of

142
Audit Trail concept in php, mysql [on hold]

Audit Trail concept in php, mysql [on hold]

I want to use Audit trail concept in php and mysql web applicationI need to track which user edit which field at what time frame? Also i need to compare the current version of saved data with previous version

128