douvcpx6526 2017-06-15 07:17
浏览 42
已采纳

Codeigniter使用外部文件替换database.php

I have two web sites using codeigniter that uses the same database configurations(hostname,username,password), just want to ask if the database configuration can be called from a external file? The thing is if i want to change my database root password i have to change the two sites database.php manually, now lets says i have 10 websites this will be a difficult task correct? i just want to change a single file so all sites can use that configuration.

I am using mysql via PHPmyadmin.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'root',
    'database' => 'MyBlog',
    'dbdriver' => 'mysqli',
  • 写回答

1条回答 默认 最新

  • dtvnbe1428 2017-06-15 09:01
    关注

    If you have need to use one configuration for all sites, you can make the file (i.e. db_config.php) and set ti somewhere to be available to all CI applications.

    db_config.php

    <?php
    
    return [
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => '',
        'password' => '',
        'database' => '',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    ];
    

    Then in your APPPATH.'config/db.php' of every application you should have:

    $db['default'] = require('/path/to/db_config.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!