在codeigniter中找不到数据库名称

时间:2017-07-28 15:52:35

标签: php codeigniter

我在我的codeigniter项目中有很多文件检查,但我没有找到数据库名称,请回答我

    $active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = DBHOST;
$db['default']['username'] = DBUSER;
$db['default']['password'] = DBPASS;
$db['default']['database'] = DBNAME;
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

3 个答案:

答案 0 :(得分:1)

通常你会将它们设置为一个env变量,它设置每个生产水平的值ex $db['default']['hostname'] = getenv('DB_HOST');

$db['default']['hostname'] = 'localhost';//ex 'localhost'
$db['default']['username'] = 'root';//username of your database
$db['default']['password'] = 'root';//password of your database
$db['default']['database'] = 'databasename';//name of data base
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';//you can leave this as is
$db['default']['pconnect'] = TRUE;//you can leave this as is
$db['default']['db_debug'] = TRUE;//you can leave this as is
$db['default']['cache_on'] = FALSE;//you can leave this as is
$db['default']['cachedir'] = '';//you can leave this as is
$db['default']['char_set'] = 'utf8';//you can leave this as is
$db['default']['dbcollat'] = 'utf8_general_ci';//you can leave this as is
$db['default']['swap_pre'] = '';//you can leave this as is
$db['default']['autoinit'] = TRUE;//you can leave this as is
$db['default']['stricton'] = FALSE;//you can leave this as is

答案 1 :(得分:0)

我看到你在这里尝试做什么,但更好的方法是创建多个数据库组,它们具有不同的数据库设置。

if(ENVIRONMENT == "production"){
    $active_group = 'production';
} else if(ENVIRONMENT == "development"){
    $active_group = 'default';
}

$active_record = TRUE;

$db['default']['hostname'] = 'XXXXXXXXX';
$db['default']['username'] = 'XXXXXXXXX';
$db['default']['password'] = 'XXXXXXXXX';
$db['default']['database'] = 'XXXXXXXXX';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

/* Production config */

$db['production']['hostname'] = 'XXXXXXXXXXX';
$db['production']['username'] = 'XXXXXXXXXXX';
$db['production']['password'] = 'XXXXXXXXXXX';
$db['production']['database'] = 'XXXXXXXXXXX';
$db['production']['dbdriver'] = 'mysql';
$db['production']['dbprefix'] = '';
$db['production']['pconnect'] = TRUE;
$db['production']['db_debug'] = TRUE;
$db['production']['cache_on'] = FALSE;
$db['production']['cachedir'] = '';
$db['production']['char_set'] = 'utf8';
$db['production']['dbcollat'] = 'utf8_general_ci';
$db['production']['swap_pre'] = '';
$db['production']['autoinit'] = TRUE;
$db['production']['stricton'] = FALSE;

您基本上将在index.php文件中设置环境变量,并从那里切换环境。这样,您就可以实现数据库设置,并且切换变得简单,不仅适用于数据库设置,还适用于您拥有的其他配置。

答案 2 :(得分:0)

DBNAME 显示它被定义为常量,我猜它必须在 constant.php中定义

您可以使用 grep notepad ++ 搜索文件功能在整个文件夹中查找“DBNAME”。这样,您将获得定义为常量的文件,以及您要查找的数据库名称。

如果您只对db name感兴趣,那么在同一个配置文件中添加以下行

<?php
die(DBNAME);

并点击项目的任何页面,它将打印数据库名称。

相关问题