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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料