.env配置问题
[database]
username = root
password = 123456
这种方式配置为什么不生效
database_username = root
database_password = 123456
这样配置才能生效
[database]
username = root
password = 123456
这种方式配置为什么不生效
database_username = root
database_password = 123456
这样配置才能生效
2019-01-22
base.php文件,找不到以下代码
在putenv("$item=$v");
是:
require __DIR__ . '/library/think/Loader.php';
// 注册自动加载
Loader::register();
// 注册错误和异常处理机制
Error::register();
// 实现日志接口
if (interface_exists('Psr\Log\LoggerInterface')) {
interface LoggerInterface extends \Psr\Log\LoggerInterface
{}
} else {
interface LoggerInterface
{}
}
// 注册类库别名
Loader::addClassAlias([
'App' => facade\App::class,
'Build' => facade\Build::class,
'Cache' => facade\Cache::class,
'Config' => facade\Config::class,
'Cookie' => facade\Cookie::class,
'Db' => Db::class,
'Debug' => facade\Debug::class,
'Env' => facade\Env::class,
'Facade' => Facade::class,
'Hook' => facade\Hook::class,
'Lang' => facade\Lang::class,
'Log' => facade\Log::class,
'Request' => facade\Request::class,
'Response' => facade\Response::class,
'Route' => facade\Route::class,
'Session' => facade\Session::class,
'Url' => facade\Url::class,
'Validate' => facade\Validate::class,
'View' => facade\View::class,
]);
if (is_file(ROOT_PATH . '.env')) {
$env = parse_ini_file(ROOT_PATH . '.env', true);
foreach ($env as $key => $val) {
$name = ENV_PREFIX . strtoupper($key);
if (is_array($val)) {
foreach ($val as $k => $v) {
$item = $name . '_' . strtoupper($k);
putenv("$item=$v");
}
} else {
putenv("$name=$val");
//写入环境变量,才能在打印$_ENV文件的时候显示出来配置的环境变量
$_ENV[$name]=$val;
}
}
}
找到thinkphp目录下的base.php文件,找到以上代码
在putenv("$item=$v");
后面加一句
$_ENV[$item]=$v;
这样将配置文件中的数组赋值给$_ENV数组即可
举报