Connect Eloquent ORM to MySQL through a port other than 3306

1

I have a couple of connections to each of them going to a different MySQL database, the issue is that one connects to a local server itself, but the other goes to a remote server and under "another port ", I handle the connections like this:

$capsule->addConnection([
'driver' => 'mysql',
'host' => LOCAL_DB_HST,
'database' => LOCAL_DB_NAM,
'username' => LOCAL_DB_USR,
'password' => LOCAL_DB_PWD,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
], "local");

$capsule->addConnection([
'driver' => 'mysql',
'host' => REMOTE_DB_HST,
'database' => REMOTE_DB_NAM,
'username' => REMOTE_DB_USR,
'password' => REMOTE_DB_PWD,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
], "remota");

It is important to clarify that I am not using Eloquent as part of Laravel ... but as a fully independent implementation.

The issue is that the remote MySQL server uses a port other than 3306 and I do not know how to tell Eloquent to use another port when connecting to the remote server as long as it retains the default port (3306) for the local connection

    
asked by elapez 22.03.2018 в 23:28
source

1 answer

1

I never used it without laravel, but I calculate that it has to work the same and if so, you can specify the port.   It would be something like this:

$capsule->addConnection([
'driver' => 'mysql',
'host' => REMOTE_DB_HST,
'port' => REMOTE_DB_PORT,
'database' => REMOTE_DB_NAM,
'username' => REMOTE_DB_USR,
'password' => REMOTE_DB_PWD,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
], "remota");

Inside Laravel the configuration of a mysql database is like that, maybe it will help you.

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],
    
answered by 26.03.2018 / 17:12
source