Vaweto's avatar
Level 18

Wrong default DB connection

I have a problem with config/database.php. My app connects with multiple databases as seen below.

return [

/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/

'fetch' => PDO::FETCH_CLASS,

/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/

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

'connections' => [

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'port'      => env('DB_PORT', 3306),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => env('DB_CHARSET', 'utf8'),
        'collation' => env('DB_COLLATION', 'utf8_unicode_ci'),
        'prefix'    => env('DB_PREFIX', ''),
        //'timezone'  => env('DB_TIMEZONE', '+00:00'),
        'strict'    => env('DB_STRICT_MODE', false),
    ],

   
    'mysql_wms' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE_WMS', 'forge'),
        'username' => env('DB_USERNAME_WMS', 'forge'),
        'password' => env('DB_PASSWORD_WMS', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
    ],

],

So the problem is that when i run php artisan migrate the application use as default the mysql_wms instead of mysql. Also when i run config('database.default) on tinker it returns mysql_wms.

  • I have already checked my env and is correct DB_CONNECTION=mysql
  • I have already run php artisan cache:clear
  • I also assign to default connection the db without use env variable. ( 'default' => 'mysql' )
0 likes
11 replies
Sinnbeck's avatar

Use php artisan config:clear (not cache)

Vaweto's avatar
Level 18

Lumen does not have php artisan config:clear .. :-(

Sinnbeck's avatar

Oh sorry missed that. Any chance you are using this to serve the website? php -S localhost:8000 -t public

If so did you try stopping it and starting it again?

Vaweto's avatar
Level 18

No, I'm not using this command.

Sinnbeck's avatar

Any chance that you are overwriting it somewhere at runtime? Try searching for

config(['database.default' => 'mysql_wms']);
Vaweto's avatar
Level 18

I did this but i haven't found anything. The weird part is that this happening only in the staging server and not on the local.

shez1983's avatar

when you say you have checked this in .env i assume you mean staging? where is your staging hosted digital ocean/aws etc?

Vaweto's avatar
Level 18

On azure . I don't think that caused by the server. I also flush memcached by nothing changed.

Sinnbeck's avatar

That should be easy to test i would assume. Zip the content and download it (env and all). Download it and unzip it locally. Test it without changing a thing

solosieg's avatar

While you say you have checked this in .Env i count on you mean staging? Wherein is your staging hosted digital ocean/aws and so on?

asdfsde's avatar

I'm learning this to use on my new website. I'm running a reviews blog that hosted on WordPress.

Please or to participate in this conversation.