title: Will I need to recompile/install php to add the mssql extension?
body: <p>I have a system that is running php, and I recently needed to add connectivity to an MSSQL database. I have FreeTDS and UnixODBC installed/configured correctly, and I can make successful queries in python, and via utilities like tsql and isql. After looking at <code>phpinfo()</code> I've discovered I don't have a 'sqlsrv' section, and there is no <code>mssql.so</code> file in my php extensions directory. </p>
  
  <p>I want to add this to my system without having to recompile/install php. Would I be able to find and download the <code>mssql.so</code> file, put it into my extensions directory, add <code>extension=/path/to/mssql.so</code> to my <code>php.ini</code> file, and reload apache to get this working? Or is there more steps I would need to take?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The system is running SLES11 with PHP 5.2</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I've managed to get the php5-mssql extension installed. I grabbed the source, extracted it, and copies these files:</p>
  
  <pre><code>ext/mssql/config.m4
  ext/mssql/php_mssql.c
  ext/mssql/php_mssql.h
  </code></pre>
  
  <p>Then, in the directory where I copied the files to, I ran <code>phpize</code> (you will need to install <code>php5-devel</code> to get this tool), and compiled the extension like so:</p>
  
  <pre><code>./configure --with-mssql=/usr/local/freetds
  make
  </code></pre>
  
  <p>I also had to add a line and comment out a line in <code>php_mssql.c</code> before it could actually compile correctly (not everyone will need to do this):</p>
  
  <pre><code>{NULL,NULL,NULL}
  /*PHP_FE_END*/
  </code></pre>
  
  <p>This created the mssql.so file in /php_mssql/modules/ (relative to where I compiled the code), which I was able to move to my extensions directory (you can find this with <code>php -i | grep extensions</code>). I added <code>extension=mssql.so</code> to my php.ini file; however, there is still no 'sqlsrv section in <code>phpinfo()</code>.</p>
  
  <p>Some connection methods seem to partially work:</p>
  
  <p>When running the following code from a shell, <code>&lt;h1&gt;Connection Success&lt;/h1&gt;</code> is shown; but when opened in a browser, nothing after the <code>mssql_connect</code> line is shown:</p>
  
  <pre><code>&lt;?php
  //*************************************************************************
  //Open Database Connection
  //*************************************************************************
  //phpinfo();
  $dbserver="MyServer";
  $dbusername="user";
  $dbpassword="pass";
  $defaultdb="DBName";
  $cn = mssql_connect($dbserver,$dbusername,$dbpassword) or die("Connection Error");
  $db = mssql_select_db($defaultdb,$cn) or die("Database Error");
  echo "&lt;h1&gt;Connection Success&lt;/h1&gt;";
  ?&gt;
  </code></pre>
  
  <p>So it looks like I'm partially getting a connection that way? When I try with a PDO object, I get another error:</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
  $con = new PDO('odbc:host=MyServer;dbname=DBName','user','pass');
  ?&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /path/to/php/file/test3.php:3
  Stack trace:
  #0 /path/to/php/file/test3.php(3): PDO-&gt;__construct('odbc:host=MySer...', 'user', 'pass')
  #1 {main}
    thrown in /path/to/php/file/test3.php on line 3
  </code></pre>
  
  <p>I've also tried the following (assuming that the PDO statement/DSN in the previous code was incorrrect):</p>
  
  <pre><code>&lt;?php
  try {
          $db = new PDO("odbc:Driver=FreeTDS; Server=MyServer; Port=1433; Database=DBName; UID=user; PWD=pass;");
  } catch (PDOException $exception) {
          die("$exception");
  }
  echo "&lt;h1&gt;Success!&lt;/h1&gt;";
  ?&gt;
  </code></pre>
  
  <p>This showed <code>&lt;h1&gt;Success!&lt;/h1&gt;</code> from the shell, but showed the following error in my web browser:</p>
  
  <pre><code>exception 'PDOException' with message 'SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source' in /path/to/php/file/test4.php:3 Stack trace: #0 /path/to/php/file/test4.php(3): PDO-&gt;__construct('odbc:Driver=Fre...') #1 {main}
  </code></pre>