0

I'm able to connect phymyadmin of remote pc, but when i try to connect to remote db, I'm getting connection refused error.

I have seen similar kind of question, but not yet answered also it is not active now.SQLSTATE[HY000] [2002] Connection refused with right port

<?php
    $servername = "192.168.1.12";
    $username = "root";
    $password = "root";

    try {
        $conn = new \PDO("mysql:host=$servername;dbname=my_db", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        echo "Connected successfully"; 
        }
    catch(\PDOException $e)
        {
        echo "Connection failed: " . $e->getMessage();
        }
?>
Jabaa
  • 1,743
  • 7
  • 31
  • 60
Geethu
  • 348
  • 6
  • 24
  • did you read this question and its answers? https://stackoverflow.com/questions/45254222/getting-error-sqlstatehy000-2002-connection-refused-on-nas-synology – R A Oct 24 '17 at 08:30
  • have you tried localhost or 127.0.0.1 instead of "192.168.1.12"? – R A Oct 24 '17 at 08:31
  • yes i'am able to connect to 127.0.0.1 @Rafail Akhmetshin – Geethu Oct 24 '17 at 08:32

1 Answers1

0

In remote pc, bind address in mysql configuration file was set to 127.0.0.1 instead of 192.168.1.12

Geethu
  • 348
  • 6
  • 24