lundi 28 mai 2018

Database [dpnmwin] not configured

I'm trying to connect 2 database on my system with laravel 5, and when I try to get data from one I skip this error

Database [dpnmwin] not configured.

my file .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=spi_intranet
DB_USERNAME=root
DB_PASSWORD=null

DB_CONNECTION_SECOND=mysql
DB_HOST_SECOND=127.0.0.1
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=dpnmwin
DB_USERNAME_SECOND=root
DB_PASSWORD_SECOND=null

My file database.php

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'spi_intranet'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

    'mysql2' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST_SECOND', '127.0.0.1'),
        'port' => env('DB_PORT_SECOND', '3306'),
        'database' => env('DB_DATABASE_SECOND', 'dpnmwin'),
        'username' => env('DB_USERNAME_SECOND', 'root'),
        'password' => env('DB_PASSWORD_SECOND', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

the error comes out when he tried to bring data from the dpnmwin database, as follows

public function index(){

     $users = DB::connection('dpnmwin')->select('select * from datos_itu');

     return view('users.list',array(
         'users' => $users
     ));

}

but if I want to bring data from my other database spi_intranet

public function index(){

    $users = User::all();

    return view('users.list',array(
            'users' => $users
    ));

}

it brings me the data without problems.

Why do not you bring me the data from my other database?

Is it a problem in the configuration?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire