<?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>Ixalon.net &#187; Work</title>
	<atom:link href="http://www.ixalon.net/category/work/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ixalon.net</link>
	<description>Chris Warren's Rather Neglected Website</description>
	<lastBuildDate>Fri, 04 Jun 2010 17:03:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress and Microsoft SQL Server</title>
		<link>http://www.ixalon.net/2008/10/wordpress-and-microsoft-sql-server/</link>
		<comments>http://www.ixalon.net/2008/10/wordpress-and-microsoft-sql-server/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 23:58:30 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.ixalon.net/?p=24</guid>
		<description><![CDATA[I really like WordPress; it&#8217;s quick to set up and easy for beginners to pick up and blog with. So I decided to start using it for projects at work. Was I in for a shock&#8230;
Our server platform at work is all Windows based. Running various editions of Windows Server 2003 and Microsoft SQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>I really like WordPress; it&#8217;s quick to set up and easy for beginners to pick up and blog with. So I decided to start using it for projects at work. Was I in for a shock&#8230;</p>
<p><span id="more-24"></span>Our server platform at work is all Windows based. Running various editions of Windows Server 2003 and Microsoft SQL Server 2005 (MSSQL). We&#8217;ve got a good robust setup with a high level of redundancy, including our SQL Server cluster; if we&#8217;re going to create websites for customers using WordPress, we want to leverage the full capabilities of our platform. This is where I hit a problem; WordPress is tightly bound to MySQL, which is normally all well and good (I&#8217;ve got no problem with MySQL), but I don&#8217;t want to set up and maintain two RDBMS when we&#8217;ve got a perfectly good one as it is.</p>
<p>And so began my quest three-day quest to get WordPress running on MSSQL.</p>
<p>First problem I had, how to get WordPress to use a database library other than PHP&#8217;s built-in MySQL support. This was an easy one thanks to the <a href="http://wordpress.org/extend/plugins/pdo-for-wordpress/">PDO (SQLite) for WordPress</a> plugin; this contains code to intercept the DB calls and rewrite them, but to SQLite&#8217;s SQL syntax. Thankfully the SQLite driver provides a good template for producing additional drivers and it didn&#8217;t take too much work to write one to rewrite MySQL syntax into T-SQL as used by MSSQL and wire it up to the PHP pdo_mssql extension. This was simple enough to do but it still didn&#8217;t work correctly, if we want to send the MSSQL equivalent of IF NOT EXISTS, we need to use a SQL batch, not a single command. Turns out when you send a batch to the library behind the PHP pdo_mssql extension (freetds) it doesn&#8217;t like it, not reading all the data back from SQL, causing the &#8220;Attempt to initiate a new SQL Server operation with results pending&#8221; error. A few tweaks to the C code of freetds changed the behaviour to mimic that often found in ODBC drivers, only returning the last result of a batch.</p>
<p>There&#8217;s probably a better way of fixing this, i.e. returning all the result sets in some manner, but I&#8217;m not sure if or how MySQL presents such things. I also think the PDO for WordPress plugin could be optimised by stripping out values from the rewritten queries and caching them as templates. Something else to look at when I&#8217;ve got some spare time.</p>
<p>Anyway, I was rather happy when WordPress&#8217;s install script successfully created the schema within the database along with all the required keys and indicies. Not for long though; as soon as I loged in every page request would be greeted by an error in the code to manage the rewrite rules. Upon closer inspection I found that something was truncating the rewrite_rules value in the wp_options table, preventing the data from being unserialised. Good old Google provided the diagnosis (but not the cure); PHP&#8217;s MSSQL PDO extension truncates long text fields to 4096 characters. Setting mssql.textsize and mssql.textlimit in php.ini didn&#8217;t help, only the native mssql extension picks these up, not the PDO extension.</p>
<p>After a of hacking around in the C source for PHP, I managed to get it to set the database options required for returning longer values. Almost there&#8230;</p>
<p>Apart from yet another error! It seems that Microsoft&#8217;s DB lib which is used behind freetds to provide the connection to SQL has another useful strange behaviour, returning empty strings as a single space. Brilliant! The most obvious side effect in WordPress was that every page and post was protected by a single-space password.</p>
<p>After not being able to find a sensible way to fix this, I wrote a horrible hack for freetds to detect result columns containing only a single space and replacing them with an empty string. This isn&#8217;t ideal, as unlikely as it is, you may actually want to store a single space in a value, but Microsoft&#8217;s aging library appears to offer no way to distinguish between &#8221; and &#8216; &#8216;.</p>
<p>At some point, when things have quietened down a bit, I&#8217;ll try to neaten up the modifications to the various libraries and plugins and release a set of patches.</p>

<div class="sociable">

<ul>
	<li class="sociablefirst"><a rel="nofollow"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.ixalon.net%2F2008%2F10%2Fwordpress-and-microsoft-sql-server%2F&amp;title=WordPress%20and%20Microsoft%20SQL%20Server&amp;bodytext=I%20really%20like%20WordPress%3B%20it%27s%20quick%20to%20set%20up%20and%20easy%20for%20beginners%20to%20pick%20up%20and%20blog%20with.%20So%20I%20decided%20to%20start%20using%20it%20for%20projects%20at%20work.%20Was%20I%20in%20for%20a%20shock...%0D%0A%0D%0AOur%20server%20platform%20at%20work%20is%20all%20Windows%20based.%20Running%20various%20editions%20" title="Digg"><img src="http://www.ixalon.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.ixalon.net%2F2008%2F10%2Fwordpress-and-microsoft-sql-server%2F&amp;title=WordPress%20and%20Microsoft%20SQL%20Server&amp;notes=I%20really%20like%20WordPress%3B%20it%27s%20quick%20to%20set%20up%20and%20easy%20for%20beginners%20to%20pick%20up%20and%20blog%20with.%20So%20I%20decided%20to%20start%20using%20it%20for%20projects%20at%20work.%20Was%20I%20in%20for%20a%20shock...%0D%0A%0D%0AOur%20server%20platform%20at%20work%20is%20all%20Windows%20based.%20Running%20various%20editions%20" title="del.icio.us"><img src="http://www.ixalon.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.ixalon.net%2F2008%2F10%2Fwordpress-and-microsoft-sql-server%2F&amp;t=WordPress%20and%20Microsoft%20SQL%20Server" title="Facebook"><img src="http://www.ixalon.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Fwww.ixalon.net%2F2008%2F10%2Fwordpress-and-microsoft-sql-server%2F" title="Technorati"><img src="http://www.ixalon.net/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.ixalon.net%2F2008%2F10%2Fwordpress-and-microsoft-sql-server%2F&amp;title=WordPress%20and%20Microsoft%20SQL%20Server&amp;annotation=I%20really%20like%20WordPress%3B%20it%27s%20quick%20to%20set%20up%20and%20easy%20for%20beginners%20to%20pick%20up%20and%20blog%20with.%20So%20I%20decided%20to%20start%20using%20it%20for%20projects%20at%20work.%20Was%20I%20in%20for%20a%20shock...%0D%0A%0D%0AOur%20server%20platform%20at%20work%20is%20all%20Windows%20based.%20Running%20various%20editions%20" title="Google Bookmarks"><img src="http://www.ixalon.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.ixalon.net%2F2008%2F10%2Fwordpress-and-microsoft-sql-server%2F&amp;title=WordPress%20and%20Microsoft%20SQL%20Server" title="Live"><img src="http://www.ixalon.net/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ixalon.net/2008/10/wordpress-and-microsoft-sql-server/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
