title: Connecting to sql server data with PHP on ubuntu
body: <p>When trying to connect to my mssql database, I get the error 
      "SQLSTATE[01002] Adaptive Server connection failed (severity 9)"</p>
  
  <p>Below is the php code I'm running</p>
  
  <pre><code>&lt;?php
  
    try {
      $hostname = "hostname.database.windows.net";
      $port = 1433;
      $dbname = "database-dev";
      $username = "dbuser";
      $pw = "dbpassword";   
      $dbh = new PDO     ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
    } catch (PDOException $e) {
      echo "Failed to get DB handle: " . $e-&gt;getMessage() . "\n";
      exit;
    }
    $stmt = $dbh-&gt;prepare("select name from master..sysdatabases where     name = db_name()");
    $stmt-&gt;execute();
    while ($row = $stmt-&gt;fetch()) {
      print_r($row);
    }  
    unset($dbh); unset($stmt);
  ?&gt;
  </code></pre>
  
  <p>And below is my odbc.ini, odbcinst.ini and freetds.conf, you can see my phpinfo() here ("<a href="http://wingedw.com/matiks/connect.php" rel="nofollow">http://wingedw.com/matiks/connect.php</a>") the driver is set to freetds and the pdo and pdo_dlib modules have been added to php 5, any clues as to why im getting error, im sure the credentials are right.</p>
  
  <p>odbc.ini </p>
  
  <pre><code>[MSSQLServer]
  Driver = FreeTDS
  Description = Any description
  Trace = No
  Server = servername
  Port = 1433
  Database = dbname
  wTDS_Verison = 7.1
  </code></pre>
  
  <p>odbcinst.ini</p>
  
  <pre><code>[FreeTDS]
  Driver      = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
  Setup           = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
  UsageCount      = 1
  </code></pre>
  
  <p>freetds.conf</p>
  
  <pre><code>[global]
      # TDS protocol version
  ;       tds version = 7.1
  
      # Whether to write a TDSDUMP file for diagnostic purposes
      # (setting this to /tmp is insecure on a multi-user system)
  ;       dump file = /tmp/freetds.log
  ;       debug flags = 0xffff
  
      # Command and connection timeouts
  ;       timeout = 100
  ;       connect timeout = 100
  
      # If you get out-of-memory errors, it may mean that your client
      # is trying to allocate a huge buffer for a TEXT field.  
      # Try setting 'text size' to a more reasonable limit 
      text size = 64512
  
  # A typical Sybase server
  [egServer50]
      host = symachine.domain.com
      port = 5000
      tds version = 7.1
  
  # A typical Microsoft server
  [MSSQLServer]
      host = servername
      port = 1433
      tds version = 7.1
  </code></pre>