<?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>dotvoid.com &#187; odbc</title>
	<atom:link href="http://www.dotvoid.com/tag/odbc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotvoid.com</link>
	<description>Experiments and thoughts in PHP and javascript</description>
	<lastBuildDate>Tue, 11 Oct 2011 12:49:15 +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>I hate ODBC</title>
		<link>http://www.dotvoid.com/2005/02/i-hate-odbc/</link>
		<comments>http://www.dotvoid.com/2005/02/i-hate-odbc/#comments</comments>
		<pubDate>Fri, 18 Feb 2005 10:38:35 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[odbc]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=114</guid>
		<description><![CDATA[
Many people don&#8217;t like the idea of putting binary files in a database. I on the other hand have always enjoyed having all data, textual and binary, in the same place. What better than having it all nicely tucked away in a comfy database. The site is handled by the version handling system and the [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>Many people don&#8217;t like the idea of putting binary files in a database. I on the other hand have always enjoyed having all data, textual and binary, in the same place. What better than having it all nicely tucked away in a comfy database. The site is handled by the version handling system and the data is backed up in the normal db backup routine.  But when the system is a RedHat 7.3 using ASP mixed with PHP with ODBC connections to an MS SQL Server I really start to grind my teeth.</p></div>
<p>I didn&#8217;t want to rewrite things for free. So when I took the site onboard I only had to rewrite the actual file uploading. As it is using SUN One ASP (former Chilisoft ASP) I had to use the Chili component for this. It all went smoothly until I tried to put the uploaded data into the database. For some reason I just couldn&#8217;t get the Recordset to be updatable.</p>
<pre>Set rs1 = Server.CreateObject("ADODB.Recordset")
sql = "select id, prodpic from product where id = '" &amp; ref &amp; "'"
rs1.Open sql, conn, 3, 3
rs1.Fields("bild").appendChunk picturechunk
rs1("bild").value = fblob
rs1.Update</pre>
<p>As I don&#8217;t really like, or know, ASP (I haven&#8217;t touched VB since VB4 was new and Microsoft said it was as fast as compiled C++) I decided that the quickest way out of this would be to convert the script to PHP. As the application is a horrible mix already I figured it wouldn&#8217;t make things worse. That should do it. No problem at all.</p>
<p>Well it was a problem. ODBC has this limitation on the size of an SQL statement. You can only send through SQL statements with a maximum of 4096 bytes (or something like that). I knew this and I also knew you solve it by using a combination of the methods odbc_prepare and odbc_execute. You have two different ways of sending binary data this way. Well the ODBC driver (Free TDS) puked on me again and again. Go figure.</p>
<p>Then as the genius I am I said to myself. Chunks, concatenation. Yeah. Something like below should work. I&#8217;ve done the same with MySQL queries in some circumstances.</p>
<pre>$fdata = base64_encode(get_file_contents($filepath));
$total = strlen($fdata);
$pos = 0;

while ($pos &lt; $total)
  {
      $len = ($pos + 2048 &gt; $total) ? $total - $pos : 2048;
      $substr = substr($fdata, $pos, $len);
      $sql = "update product set prodpic = prodpic + '$substr' where id='$ref'";
      db_exec($sql);
      $pos += $len;
  }</pre>
<p>After puzzling awhile over the weird results this gave I turned to the almighty web for answers. It turns out MS SQL Server only supports concatenation of datatypes <span style="font-weight: bold;">not capable</span> of storing large amounts of data. So for the datatypes image and text it is impossible. Wonderful.</p>
<p>So now I just save the files on the filesystem instead. Have to setup backup routines for the machine though. Something I thought would take about an hour to fix finally took more than two days of coding and research.</p>
<p>Hopefully I learn some valueable lesson from all of this but I&#8217;m sure I won&#8217;t.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2005/02/i-hate-odbc/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2005/02/i-hate-odbc/&amp;title=I+hate+ODBC" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2005/02/i-hate-odbc/&amp;t=I+hate+ODBC" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2005/02/i-hate-odbc/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2005/02/i-hate-odbc/&amp;title=I+hate+ODBC&amp;summary=%0D%0A%0D%0AMany%20people%20don%27t%20like%20the%20idea%20of%20putting%20binary%20files%20in%20a%20database.%20I%20on%20the%20other%20hand%20have%20always%20enjoyed%20having%20all%20data%2C%20textual%20and%20binary%2C%20in%20the%20same%20place.%20What%20better%20than%20having%20it%20all%20nicely%20tucked%20away%20in%20a%20comfy%20database.%20The%20site%20is%20handled%20by%20the%20version%20handling%20system%20and%20the&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2005/02/i-hate-odbc/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2005/02/i-hate-odbc/&amp;title=I+hate+ODBC" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=I+hate+ODBC+-+File: /data/app/webapp/functions.php<br />Line: 66<br />Message: Duplicate entry 'wyarW' for key 'code'&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2005/02/i-hate-odbc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ODBC and ASP with PHP on RedHat 7.3</title>
		<link>http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/</link>
		<comments>http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/#comments</comments>
		<pubDate>Tue, 04 May 2004 07:42:04 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[redhat]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=30</guid>
		<description><![CDATA[
I never thought the day would come when I would setup a system using something as old as RedHat 7.3 when not even RedHat 9 is supported any longer. Actually, I didn&#8217;t think I would ever setup a website using both PHP, ASP, SQL Server and odbc at the same time.
Well, around came a friend [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>I never thought the day would come when I would setup a system using something as old as RedHat 7.3 when not even RedHat 9 is supported any longer. Actually, I didn&#8217;t think I would ever setup a website using both PHP, ASP, SQL Server and odbc at the same time.</p>
<p>Well, around came a friend of mine with weird corporate site where ASP was mingled together with PHP. Odbc is used in both languages to call two different databases, both on SQL Server. To complicate life even further PHP pages opened ASP pages via http, inserting the ASP generated content into the output of PHP. The site also relied heavily upon GIF functionality in the GD module which is no longer supported in newer versions.</p></div>
<p>As installing and running it on a windows box failed because of compatibility issues with <a href="http://www.php.net/manual/en/ref.image.php">GD</a> my friend asked me to try getting it to work on Linux. In hindsight it would perhaps have been easier to skip the GIF functionality from start as I soon decided to not run an old GD anyway. So firstly I changed their code to use PNG instead of GIF which went very well. At this point it would probably have worked on the Windows platform but as I am sucker for *nix I never thought twice before proceeding.</p>
<p>Then came the problems. Chilisoft ASP or <a href="http://wwws.sun.com/software/chilisoft/index.html">Sun Java System Active Server Pages</a> as it is called nowadays only supported version 7.3 of RedHat linux. I tried RH 9 first but I failed to get it to work even though there are hints here and there that it is possible to make it work. (<em>No I haven&#8217;t tried RedHat Enterprise Linux yet and I still like RedHat</em>) So after several nights of frustration, trying in vain to get it to work, I downloaded version 7.3 and everything worked out of the box. The admin interface is very simple and the odbc connections for Sun ONE ASP were easy to setup as well. Splendid!</p>
<div id="attachment_31" class="wp-caption aligncenter" style="width: 314px"><a href="http://www.commodi.com/wp-content/uploads/2008/09/fs__media_mod_action_005.png"><img class="size-full wp-image-31" title="Sun ONE ASP administration console" src="http://www.dotvoid.com/wp-content/uploads/2008/09/fs__media_mod_action_005.png" alt="The ASP Administration Console" width="304" height="238" /></a><p class="wp-caption-text">Sun ONE ASP administration console</p></div>
<p>Finally I had to get the <a href="http://www.php.net/manual/en/ref.uodbc.php">odbc module</a> working for PHP as well. I decided to go with <a href="http://www.iodbc.org/">iODBC</a> from <a href="http://www.openlinksw.com/">OpenLink Software</a>. It was easy to build and after that I rebuilt PHP with odbc support. The problem was the drivers available. OpenLink software only had commercial drivers which to me seemed to install loads of unnecessary stuff for .NET, Mono, XML, POP3 and more.</p>
<p>It took me awhile to figure out that <a href="http://www.freetds.org/">FreeTDS</a>, that I had previously compiled and installed for SQL Server support, could be built to produce an odbc driver for iODBC. I just had to compile FreeTDS and IODBCin the right order. <em>First the iODBC driver manager and then FreeTDS</em>. I recompiled FreeTDS and it automatically created the odbc driver.</p>
<p>By this time I was quite tired and made a few mistakes with the configuration resulting in more unneeded frustration. Even so, it seems to work as well as it should. The only problem I can see now that I have it working is the lack of resources on the web describing the setup of PHP using odbc. As it is, information is scattered here and there and you have to put the bits and pieces together yourself. Is it that mostly professionals or companys use odbc and that they seldom find the time or reason to share their experiences? Anyway, in total it took me around six hours not counting the RH 7.3 installation. Tired but satisfied I could finally go home and get some sleep.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/&amp;title=ODBC+and+ASP+with+PHP+on+RedHat+7.3" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/&amp;t=ODBC+and+ASP+with+PHP+on+RedHat+7.3" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/&amp;title=ODBC+and+ASP+with+PHP+on+RedHat+7.3&amp;summary=%0D%0A%0D%0AI%20never%20thought%20the%20day%20would%20come%20when%20I%20would%20setup%20a%20system%20using%20something%20as%20old%20as%20RedHat%207.3%20when%20not%20even%20RedHat%209%20is%20supported%20any%20longer.%20Actually%2C%20I%20didn%27t%20think%20I%20would%20ever%20setup%20a%20website%20using%20both%20PHP%2C%20ASP%2C%20SQL%20Server%20and%20odbc%20at%20the%20same%20time.%0D%0A%0D%0AWell%2C%20around%20came%20a%20friend%20of%20mi&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/&amp;title=ODBC+and+ASP+with+PHP+on+RedHat+7.3" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=ODBC+and+ASP+with+PHP+on+RedHat+7.3+-+http://b2l.me/wux5z&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2004/05/odbc-with-php-on-redhat-73/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

