<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JimmyLi.net &#187; PHP</title>
	<atom:link href="http://jimmyli.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimmyli.net</link>
	<description></description>
	<lastBuildDate>Thu, 04 Aug 2011 21:40:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>IIS Tutorial Series (Part 2): Talking to SQL Server with PHP on IIS</title>
		<link>http://jimmyli.net/2010/08/talking-to-sql-server-with-php-on-iis/</link>
		<comments>http://jimmyli.net/2010/08/talking-to-sql-server-with-php-on-iis/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 09:09:01 +0000</pubDate>
		<dc:creator>Jimmy</dc:creator>
				<category><![CDATA[IIS Tutorial Series]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[mssql]]></category>

		<guid isPermaLink="false">http://jimmyli.net/?p=114</guid>
		<description><![CDATA[Microsoft now has an official SQL Server Driver to use with PHP on IIS. This is a huge and step forward for PHP/SQL Server developers since beginning with PHP 5.3, the usually packaged MSSQL extension has been deprecated.]]></description>
			<content:encoded><![CDATA[<p>Note: This article is Part 2 of the <a href="/iis-tutorial-series/">IIS Tutorial Series</a>.</p>
<p>Starting with a little history, before PHP 5.3, the options of getting PHP to talk to a Microsoft SQL Database Server was either using a generic database connector, such as ODBC, or PHP&#8217;s included MSSQL connector extension. The MSSQL extension was nice compared to ODBC as you didn&#8217;t have to set up a separate object (the ODBC connection object) to talk to the SQL Server. The MSSQL extension is very similar to PHP&#8217;s popular MySQL Extension as there are functions solely for that database type. Disappointingly, beginning from PHP 5.3, that MSSQL has been deprecated and no longer included with the PHP package, as it was stated to be unstable and unofficially supported (as well as maintenance stopped a long time ago). Initially, people started re-compiling PHP 5.3 on their own with the old MSSQL to get the functionality back, but like for the most of us, re-compiling PHP is not something we would want to step into.</p>
<p>Fortunately, Microsoft stepped up their game and finally started to support more open-source projects such as PHP, and created an official driver to talk to their SQL Server with PHP. In this tutorial, I will go over how to install the SQL Server Driver, and connect to an SQL Server with PHP. This tutorial is applicable for SQL Server 2000 or later, using PHP versions 5.2.4 or later.</p>
<p>Note: You&#8217;ll need to have PHP installed on the IIS Server. If not, read <a href="http://jimmyli.net/2010/02/installing-fastcgi-and-php-for-iis-6-0/">Part 1</a> of the tutorial series on how to do so.</p>
<p>First, visit Microsoft&#8217;s page to download the <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05" target="_blank">SQL Server Driver for PHP</a>. As of this writing, the driver is currently version 2.0. If your SQL Server is installed remotely (not on the same server as the IIS server), you&#8217;ll need to download the Microsoft SQL Server 2008 Native Client at Microsoft&#8217;s <a href="http://www.microsoft.com/downloads/details.aspx?familyid=B33D2C78-1059-4CE2-B80D-2343C099BCB4" target="_blank">SQL Server 2008 Feature Pack</a> site. If the SQL Server is on the same server, then you&#8217;ll already have the necessary Native Client library installed, and you can skip the following step. There are a lot of packages on that page. To quickly locate the right one, scroll down until you find a section &#8220;Microsoft SQL Server 2008 Native Client&#8221;, or you can use your web browser&#8217;s page search functionality to jump to it immediately. Download MSI package appropriate for your server.</p>
<p>If you had to download the SQL Server Native Client, run that executable to install it first. Then, execute the downloaded file for the SQL Server Driver. This will just do a self-extract to a folder. Save the extracted folder anywhere you want. In the folder will be a set of DLLs. Choose the DLL that is appropriate for the PHP package you are using. For more information on which DLL to use, look at the readme that&#8217;s also included in the folder. Copy that DLL and paste it into the &#8220;ext&#8221; directory of your PHP folder (e.g. C:\php\ext\). This adds the extension for PHP to use, and contains the SQL Server API functions you use in your code. This extension talks to the Native Client, which is the interface to the SQL Server.</p>
<p>Next, open up the php.ini in your PHP installation folder, and enable that extension. There should be a section with many lines of:<br />
<em>extension=xxxxxxxxx.dll</em></p>
<p>Add a new line that is specific for the DLL you are using. e.g. <em>extension=php_sqlsrv_53_nts_vc9.dll</em></p>
<p>Restart the IIS Server for all the settings to take effect. To check that the extensions is working, create a PHP script on your website with <a href="http://php.net/phpinfo" target="_blank">phpinfo</a> and the section for the &#8220;sqlsrv&#8221; extension should be in there somewhere.</p>
<p>That should be it for the installation. In the folder for the SQL Server driver should also be a file named <em>SQLSRV20_Help.chm</em>, which is a help file that includes the API documentation of the driver. There is an <a href="http://msdn.microsoft.com/en-us/library/ee229551%28v=SQL.10%29.aspx" target="_blank">online version</a> of the documentation as well.</p>
<p>For example, to connect to a SQL Server database with PHP, you can use something similar to the following code:</p>
<pre class="brush: plain; title: ; notranslate">$connectionInfo = array('UID'=&gt;'Username', 'PWD'=&gt;'password', 'Database'=&gt;'Northwind');
$conn = sqlsrv_connect('MY-DBSERVER', $connectionInfo);
if ($conn === false) die( print_r( sqlsrv_errors() ) );
</pre>
<p>Note: This code applies to authenticating as a SQL Server user, and not a Windows Authentication user. I have not gotten successful connection as a Windows user. If anyone knows how, please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimmyli.net/2010/08/talking-to-sql-server-with-php-on-iis/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>IIS Tutorial Series (Part 1): Installing FastCGI and PHP for IIS 6.0</title>
		<link>http://jimmyli.net/2010/02/installing-fastcgi-and-php-for-iis-6-0/</link>
		<comments>http://jimmyli.net/2010/02/installing-fastcgi-and-php-for-iis-6-0/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 06:40:00 +0000</pubDate>
		<dc:creator>Jimmy</dc:creator>
				<category><![CDATA[IIS Tutorial Series]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://jimmyli.net/?p=63</guid>
		<description><![CDATA[Beginning from PHP 5.3, PHP can only be installed on IIS via a CGI Handler, and no longer through ISAPI. In this tutorial, we'll step through the details of how to set up FastCGI and PHP on IIS.]]></description>
			<content:encoded><![CDATA[<p>Note: This article is Part 1 of the <a href="/iis-tutorial-series/">IIS Tutorial Series</a>.</p>
<p>Despite IIS 7.5 being the current stable IIS release, it is only available for servers running Windows Server 2008. However for the many of us who are still running Windows Server 2003 or Windows XP, IIS 6.0 is our only option. And many of us are still limited to that option.</p>
<p>In this tutorial I will be doing a walkthrough on installing FastCGI and PHP. For those who are a bit new to PHP on IIS, here&#8217;s a general view of what happens when a PHP page is call through the client&#8217;s web browser:<br />
When the client requests a PHP resource (.php), IIS responds by calling FastCGI. FastCGI is the interface to CGI Programs (in this case, PHP), so the web server can focus on web page requests. FastCGI is then responsible for calling the PHP executable to execute the PHP script, and return its response back to IIS. IIS then returns that response back to the client.</p>
<p><span style="text-decoration: underline;"><strong>Installing FastCGI</strong></span><br />
With the stable release of PHP 5.3 out for a while now, the only way to install PHP 5.3 on IIS is through a CGI Handler. PHP 5.2 and earlier allowed us to run PHP using ISAPI, but that option has been deprecated. For those of us intending to move forward, we would have to use CGI from now on.  We&#8217;ll go over installing the <a href="http://en.wikipedia.org/wiki/FastCGI" target="_blank">FastCGI</a> handler on IIS 6.0.</p>
<p>You can download FastCGI for IIS 6.0 <a href="http://www.iis.net/download/FastCGI" target="_blank">here</a> (version 1.5 as of this time).</p>
<p>Run the executable on the web server to install FastCGI. You may have to restart your machine for the installation to complete. When that&#8217;s done, open up IIS Manager and view the list of Web Service Extensions on the server tree. There should be a &#8220;FastCGI Handler&#8221; extension in the list. Make sure its status is set to <em>Allowed</em>. And that&#8217;s it. FastCGI is installed!</p>
<p style="text-align: center;"><a href="http://jimmyli.net/wp/wp-content/uploads/2010/02/web_service_extensions.png" target="_blank"><img class="aligncenter size-medium wp-image-69" title="Web Service Extensions" src="http://jimmyli.net/wp/wp-content/uploads/2010/02/web_service_extensions-300x170.png" alt="" width="300" height="170" /></a></p>
<p><span style="text-decoration: underline;"><strong>Installing PHP</strong></span><br />
Download the latest version of PHP for Windows <a href="http://windows.php.net/download/" target="_blank">here</a>.<br />
We&#8217;ll be doing the manual method of installation, so download the ZIP version and which is <em>Non Thread Safe</em>. It&#8217;s completely up to you whether you want to use the PHP 5.2 series or the PHP 5.3 series. Some applications may work on PHP 5.2 but not 5.3. Either one, the installation process is the same.</p>
<p>Unzip the content to somewhere on your server. I prefer the base of the C drive: C:\php\<br />
Rename the &#8220;php.ini-recommended&#8221; (or &#8220;php.ini-production&#8221; or &#8220;php.ini-development&#8221;, depending on the version of PHP) file to the name &#8220;php.ini&#8221; and make any adjustments to that configuration file. (I won&#8217;t go over that in this tutorial.) You can do this at a later time if you wish. Just like that, PHP is technically &#8220;installed&#8221; on your server.</p>
<p><span style="text-decoration: underline;"><strong>Making PHP work</strong></span><br />
Now, it&#8217;s time to make IIS understand what to do with requests that have the .php extension. When IIS hear a .php file called, we want it to let FastCGI know, so FastCGI can call PHP. To do so, we&#8217;ll have to set up the extension mapping for .php. Open up IIS Manager again and navigate to &#8220;Web Sites&#8221;. Right-click on it and select &#8220;Properties&#8221;. Select the &#8220;Home Directory&#8221; tab, and within it, select &#8220;Configuration&#8230;&#8221; A new window pops up with a listing of Application Extensions.</p>
<p style="text-align: center;"><a href="http://jimmyli.net/wp/wp-content/uploads/2010/02/application_extensions.png" target="_blank"><img class="aligncenter size-medium wp-image-76" title="Application Extensions" src="http://jimmyli.net/wp/wp-content/uploads/2010/02/application_extensions-271x300.png" alt="" width="271" height="300" /></a></p>
<p>Look for the .php extension and &#8220;Edit&#8230;&#8221; it. If it doesn&#8217;t exist, &#8220;Add&#8230;&#8221; the extension. A new windows pops up. For Executable, look for the FastCGI library. For most default installs, it should be under: C:\WINDOWS\system32\inetsrv\fcgiext.dll<br />
For Verbs, limit it to: GET,POST,HEAD<br />
Save all options.</p>
<p style="text-align: center;"><a href="http://jimmyli.net/wp/wp-content/uploads/2010/02/application_extension_mapping.png" target="_blank"><img class="aligncenter size-medium wp-image-77" title="Application Extension Mapping" src="http://jimmyli.net/wp/wp-content/uploads/2010/02/application_extension_mapping-300x169.png" alt="" width="300" height="169" /></a></p>
<p>IIS can request the FastCGI Executable when a .php resource is requested. Now, it&#8217;s time for FastCGI to talk to PHP by modifying FastCGI&#8217;s configuration file. For default installs, the config file should be located at: C:\WINDOWS\system32\inetsrv\fcgiext.ini<br />
Open it in a text editor and add the following at the bottom:</p>
<pre class="brush: plain; title: ; notranslate">[Types]
php=PHP

[PHP]
ExePath=c:\php\php-cgi.exe</pre>
<p>The <em>Types</em> is the extensions it&#8217;s listening to and the corresponding configuration it will use. So here a &#8220;php&#8221; extention will use the [PHP] configuration. The [PHP] configuration has the path to PHP&#8217;s CGI executable. This is how FastCGI knows where to find PHP. Modify the path to where PHP is located on your server.<br />
There are more options you can add, but this should get you going.</p>
<p><span style="text-decoration: underline;"><strong>Testing the Installation</strong></span><br />
Test that the installation went successfully. Restart IIS and create a website hosting a PHP file and output <a href="http://php.net/manual/en/function.phpinfo.php" target="_blank">phpinfo()</a>. If everything went well, you should see the PHP Info page with hints of FastCGI being used in there.</p>
<p style="text-align: center;"><a href="http://jimmyli.net/wp/wp-content/uploads/2010/02/phpinfo.png" target="_blank"><img class="aligncenter size-medium wp-image-78" title="PHP Info" src="http://jimmyli.net/wp/wp-content/uploads/2010/02/phpinfo-300x165.png" alt="" width="300" height="165" /></a></p>
<p><strong>Note:</strong> When I was doing this, I&#8217;ve also experienced a FastCGI error during this last step stating that &#8220;Access is denied&#8221;. I&#8217;m not sure if this is common, but I was able to fix the issue by adjusting the security permissions on the PHP installation folder. I make sure that the users: <em>Administrators</em>, <em>NETWORK SERVICE</em> and <em>SYSTEM</em> are listed. If not, add them, restart IIS, and try to load the PHP page again.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimmyli.net/2010/02/installing-fastcgi-and-php-for-iis-6-0/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>No SQL Server Library for PHP 5.3 Just Yet</title>
		<link>http://jimmyli.net/2009/08/no-sql-server-library-for-php-5-3-just-yet/</link>
		<comments>http://jimmyli.net/2009/08/no-sql-server-library-for-php-5-3-just-yet/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 04:06:53 +0000</pubDate>
		<dc:creator>Jimmy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[ODBC]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://jimmyli.net/?p=45</guid>
		<description><![CDATA[Update: This article is considered outdated. I’ve started an IIS Tutorial Series on Talking to SQL Server with PHP on IIS. Last time I posted about PHP deciding to remove the MS SQL Server Connection driver and library from the PHP 5.3 package, and mentioned that Microsoft now has its own version of the MS [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update:</strong> This article is considered outdated. I’ve started an IIS Tutorial Series on <a href="../../2010/08/talking-to-sql-server-with-php-on-iis/">Talking to SQL Server with PHP on IIS</a>.</em></p>
<p><a href="http://jimmyli.net/2009/07/installing-php-53-on-microsoft-iis/" target="_blank">Last time</a> I posted about PHP deciding to remove the MS SQL Server Connection driver and library from the PHP 5.3 package, and mentioned that Microsoft now has its <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=61BF87E0-D031-466B-B09A-6597C21A2E2A&amp;displaylang=en" target="_blank">own version</a> of the MS SQL Server driver for PHP.  I&#8217;ve decided to start playing around with it and after a few hours of no luck getting it to work with PHP 5.3 (it doesn&#8217;t show up in phpinfo), I&#8217;ve decided to do a search on it.  What I&#8217;ve found on the MSDN message boards was that the MS SQL  Server driver PHP, version 1.0 (the current and version), does not have support for PHP 5.3. (<a href="http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/9285793e-3ddb-49be-b138-d8cdccadb635" target="_blank">reference</a>)  Not until version 1.1 comes out, at least. This is rather stupid considering now there is no direct MS SQL Server driver for PHP 5.3.  The only way I know of is to use an <a href="http://www.php.net/manual/en/ref.uodbc.php" target="_blank">ODBC</a> connection.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimmyli.net/2009/08/no-sql-server-library-for-php-5-3-just-yet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

