@@ -176,6 +176,7 @@ protected function getMainSql(string $driver): string
176
176
protected function getRootDatabaseConnection (
177
177
string $ driver ,
178
178
string $ dbHost ,
179
+ string $ dbPort ,
179
180
string $ rootUser ,
180
181
string $ rootPass ,
181
182
?string $ dbName = null
@@ -186,6 +187,7 @@ protected function getRootDatabaseConnection(
186
187
[
187
188
'driver ' => $ this ->dbFactory ->getDriverName ($ driver ),
188
189
'host ' => $ dbHost ,
190
+ 'port ' => $ dbPort ,
189
191
'user ' => $ rootUser ,
190
192
'password ' => $ rootPass ,
191
193
'dbname ' => $ dbName ,
@@ -223,8 +225,14 @@ public function build(
223
225
bool $ returnSqlOnly = false ,
224
226
array $ steps = []
225
227
): string {
228
+ $ dbPort = 3306 ;
229
+ if (str_contains ($ dbHost , ': ' )) {
230
+ $ dbHost = explode (': ' , $ dbHost );
231
+ $ dbPort = $ dbHost [1 ];
232
+ $ dbHost = $ dbHost [0 ];
233
+ }
226
234
try {
227
- $ db = $ returnSqlOnly ? null : $ this ->getRootDatabaseConnection ($ driver , $ dbHost , $ rootUser , $ rootPass );
235
+ $ db = $ returnSqlOnly ? null : $ this ->getRootDatabaseConnection ($ driver , $ dbHost , $ dbPort , $ rootUser , $ rootPass );
228
236
} catch (\Exception $ e ) {
229
237
throw new \Exception (
230
238
'Problem initializing database adapter; '
@@ -260,7 +268,7 @@ public function build(
260
268
if ($ db ) {
261
269
// If we're already connected to the database, we should reconnect now using the name of
262
270
// the newly created database.
263
- $ db = $ this ->getRootDatabaseConnection ($ driver , $ dbHost , $ rootUser , $ rootPass , $ newName );
271
+ $ db = $ this ->getRootDatabaseConnection ($ driver , $ dbHost , $ dbPort , $ rootUser , $ rootPass , $ newName );
264
272
$ statements = $ this ->migrationLoader ->splitSqlIntoStatements ($ sql );
265
273
foreach ($ statements as $ current ) {
266
274
$ db ->executeQuery ($ current );
0 commit comments