Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database [] not configured Laravel 5

I create new db in phpmyadmin and new tables.

Then i do

    public function next(Request $request){
    $langs = DB::connection('mydb')->select('select * from lang');
    }

and get

Database [compgen] not configured.

in my .env

DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=123

in my config/database.php

        'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'test'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', '123'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => 'test_',
        'strict'    => false,
    ],
like image 709
Viktor Avatar asked Sep 29 '16 15:09

Viktor


People also ask

How check Laravel database connected or not?

Echo the Laravel database name in Blade/PHP This will output the name of the database or return 'none' if there is no connection. If you view it in the browser, it gives you the name of the connected database. Checking whether the application is connected to a Laravel database.

How to connect Laravel project with database?

You can connect your development database to your Laravel application in one of two ways: using the PlanetScale proxy or with a username and password. This tutorial will show you how to connect with a username and password, but you can use either option.


3 Answers

In my case I used 2 db connections and the second added was not cached, the command call: php artisan config:cache did the trick.

To see what's going on it was sufficient to output the $connections variable in DatabaseManager->configure method.

like image 117
Arthur Kushman Avatar answered Oct 13 '22 08:10

Arthur Kushman


You're using single connection, so you don't need to specify it:

$langs = DB::table('lang')->get();

You should use connection() method only when you're working with multiple DB connections.

like image 23
Alexey Mezenin Avatar answered Oct 13 '22 10:10

Alexey Mezenin


For me the connection worked in development but not in the production environment, so after a lot of searching, I had to rebuild the configuration cache and It has worked. I ran the following command in the laravel root directory:

php artisan config:cache 
like image 31
Samer Abu Gahgah Avatar answered Oct 13 '22 10:10

Samer Abu Gahgah