Trying out SQL Server 2005 drivers for PHP

Trying out SQL Server 2005 drivers for PHP

  • Comments 2

Per my last post, I thought I would check out the new PHP drivers for SQL Server 2005. From an interoperability perspective, this is really interesting for me. I 'cut my teeth' writing web applications early in my career which started on ASP (and Vsual Interdev) then moved to .NET. Over the years, in my perpetual study of web technologies, I came to use the WAMP stack for most web publishing (Windows + Apache + MySQL + PHP) because I had developed a high comfort level with the PHP script. Interestingly the 'WISP' stack never crossed my mind until recently (Windows + IIS + SQL Server + PHP), so I wanted to see how easy it could be set up, and how well it ran. The configuration was pretty straightforward although there were a couple of things that I had to research - setting up fastCGI for example.

I've outlined my steps here...To note, I put all of this together on my laptop (specs noted below).

Hardware HP Pavilion Entertainment PC
Processor Intel Core 2 Duo 2.0 GHz
RAM 4GB
OS Windows Vista Ultimate 32 bit
  1. I had previously installed Microsoft SQL Server 2005 Standard edition 
  2. I then downloaded/installed PHP non-thread-safe zip package (unpacked it and dropped it into 'c:\php')
  3. I grabbed the PHP drivers for SQL Server 2005 and dropped them into the following folder 'c:\php\ext' 
  4. Following this article, I setup FastCGI for IIS7, key steps here:
    • make sure CGI is enabled for IIS (this covers FastCGI in IIS 7.0).
      • In Windows Features, go to Internet Information Services -> World Wide Web services -> App Dev Features -> CGI


        CGI setup
      • Update the php.ini file with the following lines:
        • set fastcgi.impersonate = 1
        • set cgi.fix_pathinfo = 1
        • set cgi.force_redirect = 0
        • set open_basedir = your path to the webroot (mine is "c:\inetpub\wwwroot")
        • for the SQL driver, add the following under the 'Windows Extensions' section: extension=php_sqlsrv.dll
      • In the management console, I had to add a FastCGI handler as follows:
        • Under Services and Applications click on IIS and look for your server and server's 'HOME' menu
        • in the area for IIS, double click on Handler Mapping.
        • In the 'Actions' menu, click on 'Add Module Mapping' which pops open a wizard 
        • extension is '*.php' (no quotes)
        • In the module dropdown, click 'FastCGImodule'
        • the path should be the path to your php-cgi.exe file (mine was 'c:\php\php-cgi.exe')
        • then name it "PHP via FastCGI' or something similar

          FastCGI
  5. At this point, I dropped a default.php into the root directory and added the following code:
    <?php
    phpinfo();
    ?>
    it worked...If you need to add a default or index page to handle php, this can also be done through the management console by using the 'Default Document' feature.
  6. From here, I added some modified sample code to test connectivity to the database. In the same file as above, I added the following couple of lines of code just before the phpinfo() line - I'm using Windows Authentication on the database: 

    $serverName = "(local)";
    $connectionInfo = array( "Database"=>"Master");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    if( $conn )
    {
         echo "<div align='center'>Connection established to SQL Server on server " . $serverName . ".\n\n";
        }
    else
    {
         echo "Connection could not be established.\n";
         die( print_r( sqlsrv_errors(), true));
    }

  7. This step failed unfortunately, and after reviewing the error information, I noted that the IUSR account was unable to access SQL Server.
    I ran through the new login setup and tried again.


    IUSR

  8. I gave it another try and 'voila,' it worked - nothing fancy, but a fairly painless process. My 'success' screen...

    Connection

  9. FIN!


 

Leave a Comment
  • Please add 5 and 6 and type the answer here:
  • Post
Page 1 of 1 (2 items)