【发布时间】:2017-05-18 03:29:33
【问题描述】:
我正在尝试将数据库配置语句插入到 database.php 但无法正确构造它,我错过了单/双引号和转义引号,因为我不知道如何转义 $db 并且只有 localhost 被打印到文件中.请指导如何做到这一点。所有配置语句都需要打印到文件,即 database.php ,现在它只打印 localhost。
$data = $db['$username']['hostname'] = 'localhost';
$db['$username']['username'] = 'root';
$db['$username']['password'] = '';
$db['$username']['database'] = '$username';
$db['$username']['dbdriver'] = 'mysql';
$db['$username']['dbprefix'] = '';
$db['$username']['pconnect'] = TRUE;
$db['$username']['db_debug'] = TRUE;
$db['$username']['cache_on'] = FALSE;
$db['$username']['cachedir'] = '';
$db['$username']['char_set'] = 'utf8';
$db['$username']['dbcollat'] = 'utf8_general_ci';
$db['$username']['swap_pre'] = '';
$db['$username']['autoinit'] = TRUE;
$db['$username']['stricton'] = FALSE;
if ( ! write_file('../dropma/application/config/database.php', $data, 'a+'))
{
echo 'Unable to write the file';
}
else
{
echo 'File written!';
}
【问题讨论】:
标签: php mysql config codeigniter-2 codeigniter-3