Shahin
516
2
Laravel

Multiple database connection failed, PDOException in Connector.php line 47 SQLSTATE[HY000] [2002] A connection attempt failed

Posted 3 years ago by Shahin

Hi, I want to show simply users table info it get form my localhost and different variable show remote server users table info . I write the code example here :

In my Config/database.php:


        'shahin' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', '104.219.248.3'),
            'database'  => env('DB_DATABASE', 'laraveldb'),
            'username'  => env('DB_USERNAME', 'laraveldb_username'),
            'password'  => env('DB_PASSWORD', 'secret'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],

Route.php :

Route::get('mpdb',function(){

// Makeing an object of second DB.             
$users2 = DB::connection('shahin');
// Getting data with second DB object.
$u = $users2->table('users')->get();
echo "<pre>";
print_r($u);


});

Local Database work's properly but Remote database get error!!

ERROR :

PDOException in Connector.php line 47:
SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Please sign in or create an account to participate in this conversation.