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:

我有数据的数组可以包含数据库连接参数,但我不知道如何使其在应用程序内动态,我使用i18n作为货币和主要国家字符串我虽然将数据库连接参数存储到来自国家的i18n文件中像这样使用它__('database_array_params')看起来像这个文件:

<?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?

我觉得这是一个糟糕的方法,我怎样才能以更清洁的方式实现我的目标?

1 个解决方案

#1


0

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.

为你拥有的每个数据库创建一个php文件(假设有3个,你连接数据库的php文件是confic.php)。因此,访问的config1.php来自亚洲和大洋洲,config2.php来自Americas e config3.php来自欧洲和非洲。

You can use the rewrite rule as the example below (sample of connection from canada.

您可以使用重写规则作为下面的示例(来自加拿大的连接示例)。

RewriteCond %{REQUEST_URI} /country=CA*
RewriteRule (.+)$ /config2.php

更多相关文章

  1. 使用AJAX将数据发送到.php文件,如何从中获取数据?
  2. 使用javascript将文件输入到php文件
  3. 迭代文件夹中的CSV文件,并使用PHP将数据加载到MySQL中
  4. 用于cdn集成的文件类型的域更改正则表达式
  5. PHP基础 文件流
  6. PHP基础示例:商品信息管理系统v1.1[转]
  7. 教你如何利用php.exe运行php文件
  8. Laravel尝试在根文件夹中存储缓存文件
  9. php之简单的文件管理(基本功能)

随机推荐

  1. Android Studio怎样清空ArrayList
  2. 设置 listview 滚动条样式
  3. Android 4+ WIFI 直连
  4. adb - api -android
  5. Android中的Adapter
  6. Android Build: Tips and Tricks
  7. Pair 了解一下
  8. android 自定义progressbar进度条颜色
  9. Android中通过Intent调用其他应用的方法
  10. Android数据传递相关内容概述