Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel database connection returns undefined index error

I am developing a project using laravel 4 framework. In my database.php file I get the following error:

  Undefined index: driver 

And my connection is as following:

    $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'    => '',                      
                ),
            )
        );

I am also using environments in order to set different mysql connections. What is wrong with the code?

like image 723
Onur Avatar asked Jan 21 '26 09:01

Onur


1 Answers

In my case it was because I deleted

'default' => 'mysql',

by mistake from app/config/database.php.

like image 114
ubuntus Avatar answered Jan 23 '26 23:01

ubuntus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!