PHP, SQL Server with IIS

Installing & Configuring PHP with IIS

Download the Windows binary of PHP 5 from php.net. Unzip it to, say, C:\PHP. Open the “php.ini-dist” in C:\PHP and save it as “php.ini”. Locate the following line in php.ini:                         ; cgi.force_redirect = 1

We need to uncomment this line and change the setting to ‘0’ to run PHP under IIS, as shown below:

cgi.force_redirect = 0

Click Start -> Control Panel -> Administrative Tools -> Internet Information Services:

iis1.jpg

Select Default Web Site, right-click on it and select Properties:

iis2.jpg

Select the Home Directory tab and click on Configuration. In the Application Configuration window, select Mappings and click on the add button.

iis3.jpg

Enter the executable as C:\PHP\PHP-CGI.EXE and the extension as .php, as shown below.  

iis4.jpg

Click on OK button. This configuration enables IIS to run PHP files using PHP interpreter.  Finally, right-click on My Computer, select Properties, select Advanced tab and click on Environment Variables. In System Variables, select Path and click on Edit button. Add these paths to the variable value:                        C:\PHP;C:\PHP\EXT

Click OK to finish.

iis5.jpg

 

Configuring PHP with SQL Server  PHP supports SQL Server with a set of mssql_xxx functions. The PHP extension directory (normally \PHP\EXT) contains all the database libraries, like php_mssql.dll for SQL Server. Open php.ini. Verify that the “extension_dir=” points to the folder in which the database libraries are stored, as shown below:extension_dir = “c:\php\ext”

Next, look for the line “;extension=php_mssql.dll” in php.ini. Uncomment this line. It tells PHP to load the php_mssql.dll extension library into memory, which makes the mssql_xxx set of functions available to us.  You need the SQL client tools installed on the Web Server. The minimum requirement is the file “ntwdblib.dll”, which can be located in the \Windows\System32 folder on your SQL Server. Copy it to \Windows\System32 folder on your Web Server.  Now restart your web server, IIS. Create a file called “test.php” in notepad and enter the following:$server=”Beta”;$username=”sa”;$password=””;$sqlconnect=mssql_connect($server, $username, $password);$sqldb=mssql_select_db(“opus”,$sqlconnect);$sqlquery=”SELECT order_no FROM Orderlines;”;$results= mssql_query($sqlquery);while ($row=mssql_fetch_array($results)){echo $row[‘order_no’].”<br>\n”;}mssql_close($sqlconnect); 

Save the file in the web server folder “c:\Inetpub\wwwroot”. Open Internet Explorer and type the URL:           

http://alpha/test.php

Here Alpha is the Web Server and Beta is the Database Server. The above URL returns the query results on the browser. It is possible to execute SQL statements as well as Stored Procedures of SQL Server in a similar manner. 

Advertisements

3 thoughts on “PHP, SQL Server with IIS

  1. jorge luis

    hola que tal, ayudenme por fa he tratado de conectarme con la base de datos sql server2005 desde php y no he podido configurar bien ya que sale que hay problema estoy trabajando con IIS y ya configure mi servidor con php pero no conecta la base de datomuchos de los procedimientos que tu expicas alli no los puedo realizarya que la mssql_php.dll no esta en mi php.ini y no se hacer mas nada si saber algo porfa me escribes

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s