Skip to content

Commit fbc2646

Browse files
[Backport] Fix bug with retry connect and custom db port
Original Pull Request #14435 Fix a bug in the MySQL adapter when using non standard port Manual testing scenarios Use a database config with port, e.g. localhost:3307 On first call to _connect(), the config['host'] parameter is split into config['host'] and config['port'] In the _query() function, a situation happens that is suitable for a retry (e.g. a "MySQL has gone away" error) _connect() is called again Expected result Connection is reestablished and query tried again Actual result "Port must be configured within host parameter" exception
1 parent 1fffa00 commit fbc2646

File tree

1 file changed

+9
-0
lines changed
  • lib/internal/Magento/Framework/DB/Adapter/Pdo

1 file changed

+9
-0
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,15 @@ protected function _query($sql, $bind = [])
557557
) {
558558
$retry = true;
559559
$triesCount++;
560+
561+
/**
562+
* _connect() function does not allow port parameter, so put the port back with the host
563+
*/
564+
if (!empty($this->_config['port'])) {
565+
$this->_config['host'] = implode(':', [$this->_config['host'], $this->_config['port']]);
566+
unset($this->_config['port']);
567+
}
568+
560569
$this->closeConnection();
561570
$this->_connect();
562571
}

0 commit comments

Comments
 (0)