title: Getting Error SQLSTATE[HY000] [2002] Connection refused on NAS Synology
body: <p>I am making an under construction page which is hosted on my Synology NAS.</p>
  
  <p>Visitors can subscribe with their email and get informed when the website will be available.</p>
  
  <p>I have trouble with the database and PHP code that add the email to the database.</p>
  
  <p>If the server name is <code>localhost</code>, I get the following error: </p>
  
  <blockquote>
    <p>SQLSTATE[HY000] [2002] No such file or directory</p>
  </blockquote>
  
  <p>When it is <code>127.0.0.1</code> or <code>127.0.0.1:3306</code>, I get the error below:</p>
  
  <blockquote>
    <p>SQLSTATE[HY000] [2002] Connection refused</p>
  </blockquote>
  
  <p>I didn't find the solution yet on Stackoverflow.</p>
  
  <p>Here the PHP code:</p>
  
  <pre><code>&lt;?php
  
  $servername = "localhost";
  $username   = "id";
  $password   = "password";
  $dbname     = "dbname";
  
  try {
      $conn = new PDO( "mysql:host=$servername;dbname=$dbname", $username, $password );
      $conn-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
      $sql = "INSERT INTO email ( email ) VALUES ( '$email' )";
  
      $conn-&gt;exec( $sql );
      echo "New record created successfully";
  }
  
  catch( PDOException $e )
  {
      echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
  }
  $conn = null;
  </code></pre>
  
  <p>Why am I getting this error?</p>