0

I am building a central website (Laravel) which will connect different Laravel applications hosted in different DirectAdmin hosting.

I am getting this error-- SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: SELECT * FROM users LIMIT 10)

How can i connect remote database hosted in DirectAdmin??

This is what I am using to connect another database:

'mysql2' => [
    'driver' => 'mysql',
    'host' => '**.***.***.**',
    'port' => '3306',
    'database' => 'db_name',
    'username' => 'db_user',
    'password' => 'dppass',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'prefix_indexes' => true,
    'strict' => false,
    'engine' => null,
],

And from controller:

public function adminHome(){
    $news = \DB::connection('mysql2')->select("SELECT * FROM users LIMIT 10");
    dd($news);
 }
Nasir Khan
  • 753
  • 1
  • 9
  • 22
  • 1
    What is your question? – Don't Panic Feb 14 '19 at 08:56
  • i am unable to connect – Nasir Khan Feb 14 '19 at 09:58
  • You will get a better response here if you edit your question and describe your problem. `unable to connect` does not tell us anything - do you see an error? What is it? Please read the [how to ask guide](https://stackoverflow.com/questions/how-to-ask). – Don't Panic Feb 14 '19 at 09:59
  • This is the error: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: SELECT * FROM users LIMIT 10) – Nasir Khan Feb 14 '19 at 10:03
  • Great so now it becomes clear the problem is with the remote server. Is it set up to allow remote connections? https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql – Don't Panic Feb 14 '19 at 10:04
  • I already solve this. Thank you for cooperation. – Nasir Khan Feb 14 '19 at 10:53
  • Add your answer so it will help someone else in future. SO is meant to help everyone, not just you! :-) – Don't Panic Feb 14 '19 at 10:54

1 Answers1

2

I solved this problem. Just need to add host name to Remote host. From User panel go MySQL Menu > choose a Database > and add your host. enter image description here

Nasir Khan
  • 753
  • 1
  • 9
  • 22