Skip to content

Commit

Permalink
No explicit USE database statement (#54132)
Browse files Browse the repository at this point in the history
* No explicit `USE database` statement

No need to explicitly send another `USE database` statement. The database is already selected via the DSN string.

Multiple reasons for this:
- One less round trip per connection
- No connection pinning when used with a proxy (e.g. RDS Proxy).

* Update MySqlConnector.php

* Update MySqlConnector.php

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
TheLevti and taylorotwell authored Jan 9, 2025
1 parent e0a81ee commit d5aceb8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function connect(array $config)
// connection's behavior, and some might be specified by the developers.
$connection = $this->createConnection($dsn, $config, $options);

if (! empty($config['database'])) {
if (! empty($config['database']) &&
(! isset($config['use_db_after_connecting']) ||
$config['use_db_after_connecting'])) {
$connection->exec("use `{$config['database']}`;");
}

Expand Down

0 comments on commit d5aceb8

Please sign in to comment.