laravel database connection returns undefined index error

前端 未结 6 950
野趣味
野趣味 2021-01-22 16:53

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

  Undefined index: driver 

And my conne

相关标签:
6条回答
  • 2021-01-22 17:11

    I solved my problem by adding some permissions. My .env file was exists but wasn't readable. I just added 755 permission.

    0 讨论(0)
  • 2021-01-22 17:16

    In my case it was because I deleted

    'default' => 'mysql',
    

    by mistake from app/config/database.php.

    0 讨论(0)
  • 2021-01-22 17:17

    If you have multiple different connections (for example to multiple databases on the same host) and it doesn't make sense to set a default connection, you can specify a connection in the Model class.

    <?php 
    namespace App\Http\Models;
    
    use Illuminate\Database\Eloquent\Model;
    
    class Character extends Model {
    
        protected $connection = 'my_db_connection_name_here';
    }
    

    This would be on the of the connections defined in config/database.php.

    0 讨论(0)
  • 2021-01-22 17:19

    Go to root directory .env This values are taken first.

    0 讨论(0)
  • 2021-01-22 17:29

    Moving the 'driver' key up a level should fix the issue.

    $connections = array(
        'mysql' => array(
            'read' => array(
                'host'      => 'localhost',
                'database'  => 'app_system',
                'username'  => 'root',
                'password'  => 'root',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
            ),
            'write' => array(
                'host'      => 'localhost',
                'database'  => 'app_system',
                'username'  => 'root',
                'password'  => 'root',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
            ),
            'driver' => 'mysql'
        ),
    

    Most of the other params that are shared can me moved as well

    $connections = array(
        'mysql' => array(
            'read' => array(
                'host'      => 'localhost',
            ),
            'write' => array(
                'host'      => 'localhost',
            ),
            'driver'    => 'mysql',
            'database'  => 'app_system',
            'username'  => 'root',
            'password'  => 'root',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),
    
    0 讨论(0)
  • 2021-01-22 17:33

    This happens to me because I deleted

    'default' =>env('DB_CONNECTION', 'mysql'),
    

    From app/config/database.php. It's necesary have a default connection

    0 讨论(0)
提交回复
热议问题