我正在使用 laravel 4 框架开发一个项目。在我的 database.php 文件中,出现以下错误:
Undefined index: driver
我的连接如下:
$connections = array(
'mysql' => array(
'read' => array(
'host' => 'localhost',
'driver' => 'mysql',
'database' => 'app_system',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'write' => array(
'host' => 'localhost',
'driver' => 'mysql',
'database' => 'app_system',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
'mysql2' => array(
'read' => array(
'host' => 'localhost',
'driver' => 'mysql',
'database' => 'app_userdata',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'write' => array(
'host' => 'localhost',
'driver' => 'mysql',
'database' => 'app_userdata',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
)
);
我也在使用环境来设置不同的 mysql 连接。代码有什么问题?
最佳答案
在我的例子中是因为我删除了
'default' => 'mysql',
来自 app/config/database.php 的错误。
关于php - laravel 数据库连接返回未定义索引错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21228148/