Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FrenchFryNinja's avatar

Connection Timeout

Hello,

Running into a strange issue with database connections. I have 3 different connections running in my Laravel application. The third one can't connect. We continue to get a connection timeout error but only on the third connection.

The config/database.php has these 3:

        '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' => false,
            'engine' => null,
            'options'   => [
                \PDO::ATTR_EMULATE_PREPARES => true
            ]
        ],
        'registration-mysql' => [
            'driver' => 'mysql',
            'host' => env('REG_DB_HOST', '127.0.0.1'),
            'port' => env('REG_DB_PORT', '3306'),
            'database' => env('REG_DB_DATABASE', 'forge'),
            'username' => env('REG_DB_USERNAME', 'forge'),
            'password' => env('REG_DB_PASSWORD', ''),
            'unix_socket' => env('REG_DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

        'patient-portal' => [
            'driver' => 'mysql',
            'host' => env('PORTAL_DB_HOST', 'tinkerbell'),
            'port' => env('PORTAL_DB_PORT', '3306'),
            'database' => env('PORTAL_DB_DATABASE', 'forge'),
            'username' => env('PORTAL_DB_USERNAME', 'forge'),
            'password' => env('PORTAL_DB_PASSWORD', ''),
            'unix_socket' => env('PORTAL_DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

The first two are working. Any time we try to access data on the third database it fails for "Connection Timeout."

Within the model the connection string is specified:

class NPPRegistrationSnapshot extends Model
{
    protected $connection = 'patient-portal';
    protected $table = 'NPP_registration_snapshots';
//... more irrelevant code

When we shift the tables around to either of the other two databases everything works fine. I'm really at a loss here as I have no idea. The only error we get fails around that code and simply says:

SQLSTATE[HY000] [2002] Connection timed out

Help me Obi-wan Kenobi. You're my only hope.

0 likes
2 replies
jlrdw's avatar

The database credentials may be wrong, try connecting to the database with phpmyadmin using same credentials, can you connect?

FrenchFryNinja's avatar

@jlrdw Yup. Connect just fine from the web server to the db server using those credentials targetting that database.

Please or to participate in this conversation.