Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php artisan db command does not work when separate read and write hosts are configures in db config #40186

Closed
aleexdhillon opened this issue Dec 28, 2021 · 1 comment · Fixed by #40226

Comments

@aleexdhillon
Copy link

  • Laravel Version: 8.77.1
  • PHP Version: 7.4.27
  • Database Driver & Version:
    mysql Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Description:

I have configured separate read and write connections in database config file, like below

Screenshot 2021-12-28 153939

And when running the php artisan db it cannot find the host and throw exception.

Screenshot 2021-12-28 154159

Steps To Reproduce:

  1. Setup the separate read write connections for mysql in database config
    'read' => [ 'host' => [ env('DB_HOST_SLAVE', '127.0.0.1') ], ], 'write' => [ 'host' => [ env('DB_HOST_MASTER', '127.0.0.1') ], ],
  2. Run php artisan db or php artisan db mysql
@jelib3an
Copy link
Contributor

jelib3an commented Jan 2, 2022

You can use php artisan db --read or php artisan db --write to specify which host to use. But it appears there is a bug with that too. It doesn't work if host is an array...

This works though

'read' => [
    'host' => env('DB_HOST_SLAVE', '127.0.0.1'),
],
'write' => [
    'host' => env('DB_HOST_MASTER', '127.0.0.1'),
],

But this does NOT...

'read' => [
    'host' => [
        env('DB_HOST_SLAVE', '127.0.0.1'),
    ],
],
'write' => [
    'host' => [
        env('DB_HOST_MASTER', '127.0.0.1'),
    ],
],

jelib3an added a commit to jelib3an/framework that referenced this issue Jan 2, 2022
taylorotwell added a commit that referenced this issue Jan 2, 2022
* fixes #40186 : use first host if multiple

* Update DbCommand.php

Co-authored-by: Taylor Otwell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@jelib3an @aleexdhillon and others