我有两个数据库配置,一个用于生产,一个用于开发:
// app/config/database.php
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => $_SERVER['RDS_HOSTNAME'],
'database' => $_SERVER['RDS_DB_NAME'],
'username' => $_SERVER['RDS_USERNAME'],
'password' => $_SERVER['RDS_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
)
// app/config/development/database.php
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => $_SERVER['MYSQL_PORT_3306_TCP_ADDR'],
'database' => $_SERVER['MYSQL_ENV_MYSQL_DATABASE'],
'username' => $_SERVER['MYSQL_ENV_MYSQL_USER'],
'password' => $_SERVER['MYSQL_ENV_MYSQL_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
)
存在相关的数据库环境变量(以 开头的那些MYSQL_
),并且在运行 migrate 命令时:
php artisan migrate --env=development
抛出以下异常:
{
"error":{
"type":"ErrorException",
"message":"Undefined index: RDS_HOSTNAME",
"file":"/var/www/app/config/database.php",
"line":50
}
}
当我什至不想使用生产配置时,为什么 Laravel 会关心我的生产配置中的环境变量是否不存在?我该如何解决这个问题?