I have arrays of data that can contain the database connection parameters but i dont know how to make it dynamic inside the application, i used i18n for currency and major country strings i though on storing this database connection params into the i18n files from country and just use it like this __('database_array_params') looking like this file:
<?php
return array(
'CountryName' => 'Perú',
'CountryForVariable' => 'perú',
'locale_id' => 'pe',
'CurrencyForPricing' => 'Soles',
'CurrencyIsoCode' => 'PEN',
'CurrencySymbol' => 'S/',
'CurrencySign' => 'S/. ',
'CountryLat' => '-12.046374',
'CountryLong' => '-77.042793',
'TopCities' =>
array(
array(
'CityName' => 'Lima',
'PostalCode' => 'Blah'
),
array(
'CityName' => 'Cusco',
'PostalCode' => 'Blah'
),
array(
'CityName' => 'Puno',
'PostalCode' => 'Blah'
),
array(
'CityName' => 'Arequipa',
'PostalCode' => 'Blah'
)
),
'default' =>
array(
'type' => 'MySQL',
'connection' => array(
'hostname' => '127.0.0.1',
'database' => 'database_name',
'username' => 'root',
'password' => '123',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => FALSE,
),
);
i feel this is a bad approach how can i get my objective with a cleaner approach?
This is a very, very dirt solution but maybe can help.
Create a php file for every database you have (let's suppose there are 3 and your php file to connect the database is confic.php). So, config1.php for access come from Asia and Oceania, config2.php to Americas e config3.php to Europe and Africa.
You can use the rewrite rule as the example below (sample of connection from canada.
RewriteCond %{REQUEST_URI} /country=CA*
RewriteRule (.+)$ /config2.php