<?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; mssql</title>
	<atom:link href="http://jimmyli.net/tag/mssql/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimmyli.net</link>
	<description>Join the dark side</description>
	<lastBuildDate>Wed, 08 Sep 2010 07:41:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.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;">$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>0</slash:comments>
		</item>
		<item>
		<title>Finally a working SQL Server Driver for PHP 5.3</title>
		<link>http://jimmyli.net/2009/09/finally-a-working-sql-server-driver-for-php-5-3/</link>
		<comments>http://jimmyli.net/2009/09/finally-a-working-sql-server-driver-for-php-5-3/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 21:17:25 +0000</pubDate>
		<dc:creator>Jimmy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ms sql]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[PHP 5.3]]></category>

		<guid isPermaLink="false">http://jimmyli.net/?p=52</guid>
		<description><![CDATA[Update: I’ve started an IIS Tutorial Series on Talking to SQL Server with PHP on IIS which contains more details of this installation. It&#8217;s been a while since I&#8217;ve touched on the issue of having PHP 5.3 talk to a MS SQL Server on IIS (without using ODBC or other connection methods).  Last time I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update:</strong> 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> which contains more details of this installation.</em></p>
<p>It&#8217;s been a while since I&#8217;ve touched on the issue of having PHP 5.3 talk to a MS SQL Server on IIS (without using ODBC or other connection methods).  <a href="/2009/08/no-sql-server-library-for-php-5-3-just-yet/">Last time</a> I&#8217;ve mentioned that Microsoft has an official SQL Server Driver (v1.0) for PHP to talk to a SQL Server only to find that it doesn&#8217;t work for PHP pre-v5.3, which, we didn&#8217;t really need anyway because PHP already came with a MS SQL Library driver (which was removed from 5.3) that <a href="/2009/03/php-unable-to-connect-to-mssql/">somewhat works</a>.</p>
<p>However, after starting to play around with PHP 5.3 with SQL Server again I&#8217;ve noticed that Microsoft finally release <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9&amp;displaylang=en" target="_blank">v1.1 of the SQL Server Driver</a>, one that was stated to work with PHP 5.3 on IIS. Lo and behold, I was finally able to get it to work.  Even better, the package also came with an offline documentation on installing the driver and the whole API Reference.  Very nice.  For those who are interested, here is the documentation online, the lo-bandwidth version (no MS Frames):<br />
<a href="http://msdn.microsoft.com/en-us/library/cc296172%28SQL.90,loband%29.aspx" target="_blank">SQL Server Driver v1.1 for PHP</a></p>
<p>Note that if your SQL Server is on another server from the PHP server, you&#8217;ll also need to install the SQL Native Client data access library on the PHP server.  (If it is on the same server, the installation of SQL Server already installs this package.)  It is highly recommended to use the latest version that works with SQL Server 2008.  It took me a while to find it (the 2005 version link is rampantly posted everyhere), but you can find it officially here:<br />
<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&amp;displaylang=en" target="_blank">Microsoft SQL Server 2008 Feature Pack, August 2008</a></p>
<p>Near the bottom of the page you&#8217;ll find &#8220;Microsoft SQL Server 2008 Native Client&#8221;.  Get the one that&#8217;s appropriate for your machine.  Despite it saying 2008, it should be backwards compatible with earlier versions of SQL Server.  I&#8217;ve tried it as far as SQL Server 2000 (on IIS 6.0) and was able to connect and query successfully (I haven&#8217;t tested for limitations and such, if any.)</p>
<p>And there you have it.  The official method to talk to a MS SQL Server on IIS with PHP 5.3, straight from Microsoft themselves.</p>
<p><span style="text-decoration: underline;">Updated: October 09, 2009</span><br />
The version of the SQL Driver 1.1 that was released in August was a preview release version.  Microsoft officially released the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9&amp;displaylang=en" target="_blank">final version</a> of SQL Server Driver 1.1 on October 6th.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimmyli.net/2009/09/finally-a-working-sql-server-driver-for-php-5-3/feed/</wfw:commentRss>
		<slash:comments>2</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>1</slash:comments>
		</item>
		<item>
		<title>PHP Unable to Connect to MSSQL</title>
		<link>http://jimmyli.net/2009/03/php-unable-to-connect-to-mssql/</link>
		<comments>http://jimmyli.net/2009/03/php-unable-to-connect-to-mssql/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 07:15:59 +0000</pubDate>
		<dc:creator>Jimmy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[ntwdblib]]></category>

		<guid isPermaLink="false">http://jimmyli.net/?p=28</guid>
		<description><![CDATA[Update: This article is considered outdated, and is only valid for PHP versions before 5.3. I’ve started an IIS Tutorial Series on Talking to SQL Server with PHP on IIS, which is valid for any versions of PHP 5.2.4 and later. I have been pulling my hair trying for many hours to connect to a [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update:</strong> This article is considered outdated, and is only valid for PHP versions before 5.3. I’ve started an IIS Tutorial Series on <a href="http://jimmyli.net/2010/08/talking-to-sql-server-with-php-on-iis/">Talking to SQL Server with PHP on IIS</a>, which is valid for any versions of PHP 5.2.4 and later.</em></p>
<p>I have been pulling my hair trying for many hours to connect to a MSSQL server remotely with PHP.  I was able to connect using ODBC but I wanted a more elegant and native solution.  Trying to connect using PHP&#8217;s MSSQL database library constantly gave me the error:</p>
<pre class="brush: sql;">Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 172.xxx.xxx.xxx</pre>
<p>I&#8217;ve tried using the computer name and several other solutions.  Upon doing a lot of research and reading the user notes on the PHP website, and trying out several solutions before finding out a working solution.  I&#8217;ve found that the file ntwdblib.dll packaged with PHP5 (currently 5.2.9-1) is an old version (2000.2.8.0).  Most people suggested replacing it with the later version, 2000.80.194.0.</p>
<p>Click here to download this version of the file: <a href="http://jimmyli.net/wp/wp-content/uploads/2009/03/ntwdblib.zip">ntwdblib.dll</a></p>
<p>I&#8217;ve replaced the file and restarted my IIS webserver and the connection was successful!  I hope this helps for those searching for the solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimmyli.net/2009/03/php-unable-to-connect-to-mssql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
