title: php can't connect to sql server 2008 (using pdo dblib)
body: <p>I have a SQL server 2008 R2 (running on Windows server 2008 64bit), which I'm trying to connect from PHP</p>
  
  <p>My PHP server configuration:</p>
  
  <p>CentOS 6.6</p>
  
  <p>PHP 5.5.24 (compiled --with-mssql=/usr/local/freetds --with-pdo-dblib=/usr/local/freetds)</p>
  
  <p>Apache 2.4.12</p>
  
  <p>SELinux is disabled (according to this solution: <a href="https://stackoverflow.com/questions/17496915/pdo-dblib-accessing-sql-server-2008-and-2012">PDO DBLIB accessing SQL Server 2008 and 2012</a>)</p>
  
  <p>I wrote the following PHP code to connect to the SQL server:</p>
  
  <pre><code>try {
      require "classes/mypdo.class.php";
      $pdo = new MyPDO('dblib:dbname=myDB;host=myServer', 'myUser', 'myPassword');
      $pdo-&gt;debug = true;
  } catch (PDOException $e) {
      die("Connection failed: {$e-&gt;getMessage()}");
  }
  </code></pre>
  
  <p>The connection failed with an error: </p>
  
  <pre><code>Connection failed: SQLSTATE[HY000] Unknown host machine name (severity 2)
  </code></pre>
  
  <p>I tried other DSN syntaxes like:</p>
  
  <pre><code>$pdo = new MyPDO('dblib:host=192.168.0.10', 'myUser', 'myPassword');
  $pdo = new MyPDO('dblib:host=192.168.0.10:1433', 'myUser', 'myPassword');
  $pdo = new MyPDO('dblib:host=myServer', 'myUser', 'myPassword');
  </code></pre>
  
  <p>and many other variations...
  When I use an IP address instead of DSN the error is:</p>
  
  <pre><code>Connection failed: SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
  </code></pre>
  
  <p>/etc/freetds.conf</p>
  
  <pre><code>[global]
  tds version = 7.1
  dump file = /tmp/freetds.log
  timeout = 10
  connect timeout = 10
  text size = 64512
  client charset = UTF-8
  
  [myServer]
  host = 192.168.0.10
  port = 1433
  tds version = 7.1
  </code></pre>
  
  <p>I suspect that PHP ignoring freetds.conf (can't confirm it).</p>
  
  <p>When I use tsql the connection is working.</p>
  
  <pre><code>tsql -S myServer -U MyUser -P MyPassword
  locale is "en_US.UTF-8"
  locale charset is "UTF-8"
  using default charset "UTF-8"
  1&gt; 
  </code></pre>
  
  <p>What is the reason that PHP refusing to connect to the SQL server?</p>