title: Not able to connect to MySQL server using PDO
body: <p>I have a PHP script which I use to connect to a MySQL database. Connection through mysql_connect works perfectly, but when trying with PDO I get the following error: </p>
  
  <pre><code>SQLSTATE[HY000] [2005] Unknown MySQL server host 'hostname' (3)
  </code></pre>
  
  <p>the code I use to connect is below: </p>
  
  <pre><code>    &lt;?php  
      ini_set('display_errors', 1);
      error_reporting(E_ALL);
  
      $hostname_localhost ="hostname";  
      $database_localhost ="dbname";  
      $username_localhost ="user";  
      $password_localhost ="pass";  
      $user = $_GET['user'];  
      $pass = $_GET['pass'];
  
      try{
          $dbh = new PDO("mysql:host=$hostname_localhost;dbname=$database_localhost",$username_localhost,$password_localhost);
          echo 'Connected to DB';
          $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $stmt = $dbh-&gt;prepare("SELECT check_user_company(:user,:pass)");
          $stmt = $dbh-&gt;bindParam(':user',$user,PDO::PARAM_STR, 16);
          $stmt = $dbh-&gt;bindParam(':pass',$pass,PDO::PARAM_STR, 32);
  
          $stmt-&gt;execute();
  
          $result = $stmt-&gt;fetchAll();
  
          foreach($result as $row)
          {
              echo $row['company_id'].'&lt;br /&gt;';
          }
  
          $dbh = null;
      }
      catch(PDOException $e)
      {
          echo $e-&gt;getMessage();
      } 
      ?&gt;  
  </code></pre>
  
  <p>Thanks in advance</p>