title: Apache 2.4.7 on Ubuntu 14.04 will not connect to MSSQL through PHP 5.5
body: <p>I am trying to connect to a remote MSSQL server using the platforms listed in the title.  I have FreeTDS and all the relevant ODBC packages installed.  Here is my freetds.conf:</p>
  
  <pre><code>#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
  #
  # This file is installed by FreeTDS if no file by the same 
  # name is found in the installation directory.  
  #
  # For information about the layout of this file and its settings, 
  # see the freetds.conf manpage "man freetds.conf".  
  
  # Global settings are overridden by those in a database
  # server specific section
  [global]
          # TDS protocol version
  ;   tds version = 4.2
  
      # 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 = 10
  ;   connect timeout = 10
  
      # 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
  
  [DEVSQL]
      host = x.x.x.x
      instance = DEVSQL
      tds version = 8.0
  </code></pre>
  
  <p>Here is my odbc.ini:</p>
  
  <pre><code>[ODBC Data Sources]
  DEVSQL = FreeTDS Connection Server
  
  [DEVSQL]
  Description = MSSQL Server
  Driver = freetds
  ServerName = DEVSQL
  Database = test
  TDS_Version = 8.0
  </code></pre>
  
  <p>Here is my PHP code:</p>
  
  <pre><code>&lt;?php
  $dbname = "test";
  $servername = "DEVSQL";
  $username = "myuser";
  $password = "mypassword";
  
  try{
  $db = new PDO('odbc:Driver=FreeTDS; Server='.$servername.'; Database='.$dbname.'; UID='.$username.'; PWD='.$password.';');
  Database='.$dbname.'; UID='.$username.'; PWD='.$password.';');
  }
  catch(PDOException $exception){
  die("Unable to open database.&lt;br /&gt;Error message:&lt;br /&gt;&lt;br /&gt;$exception.");
  }
  echo '&lt;h1&gt;Successfully connected!&lt;/h1&gt;';
  ?&gt;
  </code></pre>
  
  <p>I am able to connect just fine using the following commands in the terminal:</p>
  
  <pre><code>TDSVER=8.0 tsql -S devsql -U myuser -P mypassword
  </code></pre>
  
  <p>as well as:</p>
  
  <pre><code>isql -v devsql myuser mypassword
  </code></pre>
  
  <p>But when I browse to index.php in FireFox I get the following error:</p>
  
  <blockquote>
    <p>exception 'PDOException' with message 'SQLSTATE[08001]
    SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect
    to data source' in /var/www/html/index.php:16 Stack trace: #0
    /var/www/html/index.php(16): PDO->__construct('odbc:Driver=Fre...') #1
    {main}.</p>
  </blockquote>
  
  <p>Any help much appreciated!  Alos, if anyone has a better way to connect to sql server from a linux box using php, I'm all ears.  Thanks again!</p>
  
  <p><strong>EDIT:</strong> I forgot to mention: Ubuntu and Apache are running inside a VM instance on a Win7 host.  The Win7 environment on that same machine is where the SQL server is running.  I'm not sure if that's relevant since they are communicating just fine, but thought I'd throw it out there.</p>