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

5.3 Can't use multiple connection while they are the same driver #17747

Closed
Hanson opened this Issue Feb 3, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@Hanson

Hanson commented Feb 3, 2017

I'm using two connections, both of them are mysql, and I found out no matter how it always query the first one , which is the default one .

And I look up the ConnectionFactory code, and there might have some problem

protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
    {
        if ($this->container->bound($key = "db.connection.{$driver}")) {
            return $this->container->make($key, [$connection, $database, $prefix, $config]);
        }

        switch ($driver) {
            case 'mysql':
                return new MySqlConnection($connection, $database, $prefix, $config);
            case 'pgsql':
                return new PostgresConnection($connection, $database, $prefix, $config);
            case 'sqlite':
                return new SQLiteConnection($connection, $database, $prefix, $config);
            case 'sqlsrv':
                return new SqlServerConnection($connection, $database, $prefix, $config);
        }

        throw new InvalidArgumentException("Unsupported driver [$driver]");
    }

When the first connection is make by the container, the second one will be the same as the first one

public function make($abstract, array $parameters = [])
    {
        $abstract = $this->getAlias($this->normalize($abstract));

        if (isset($this->instances[$abstract])) {
           // second one will go here
            return $this->instances[$abstract];
        }
    ...
  }

So , when I try to use DB::connection('mysql2')->getName(), it will return mysql1 intead of mysql2

see PR #17748

@Hanson Hanson changed the title from Can't use multiple connection while the are the same driver to Can't use multiple connection while they are the same driver Feb 3, 2017

@Hanson Hanson changed the title from Can't use multiple connection while they are the same driver to 5.3 Can't use multiple connection while they are the same driver Feb 3, 2017

@themsaid

This comment has been minimized.

Member

themsaid commented Feb 3, 2017

Please upgrade to 5.4 and check if the problem still exists.

@Hanson

This comment has been minimized.

Hanson commented Feb 3, 2017

5.4 fixed this problem but I think 5.3 should fix this

@kieranheadley

This comment has been minimized.

kieranheadley commented Oct 11, 2017

Is there a fix for this without upgrading to 5.4?

@GrahamCampbell

This comment has been minimized.

Member

GrahamCampbell commented Oct 11, 2017

Unforutnately, it's not standard practice to fix bugs in non-supported versions. Please upgrade to Laravel 5.5 LTS as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment