<?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; mysql</title>
	<atom:link href="http://www.dotvoid.com/tag/mysql/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>PHP development on Mac &#8211; my experience</title>
		<link>http://www.dotvoid.com/2011/07/php-development-on-mac-my-experience/</link>
		<comments>http://www.dotvoid.com/2011/07/php-development-on-mac-my-experience/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 12:13:34 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[gimp]]></category>
		<category><![CDATA[inkscape]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[omnigraffle]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://www.dotvoid.com/?p=466</guid>
		<description><![CDATA[A while ago I saw a lot of people writing about their PHP development environment and tools. I didn&#8217;t get around to it at the time but yesterday I found me some time to write down my experiences of moving from Linux to MacOS X as primary OS for PHP  and web development
Me and my [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I saw a lot of people writing about their PHP development environment and tools. I didn&#8217;t get around to it at the time but yesterday I found me some time to write down my experiences of moving from Linux to MacOS X as primary OS for PHP  and web development</p>
<p>Me and my partner in <a href="http://www.dotvoid.se/index.en.html">Dotvoid, a small web development and integration company,</a> have used linux as a client OS for more than a decade. All the tools I needed for developing are there already; emacs, apache, php, MySQL, xdebug, other scripting languages, various compilers, OpenOffice and so much more. For my partner, <a href="http://www.gimp.org/">Gimp</a> and <a href="http://inkscape.org/">Inkscape</a> have provided all the functionality for producing both designs and graphics. And all for free. Fantastic. Even so, a few months ago I suddenly decided it was time to abandon our ugly plastic laptops from Dell and Sony. I ordered two Macbook Pro. I haven&#8217;t used or even touched a Macintosh since 1995. But hey, they look good.</p>
<p>We soon discovered that some things aren&#8217;t as user friendly as we exptected. The multitouch trackpad with it&#8217;s gestures is wonderful. My partner still use Inkscape and <a href="http://www.gimp.org/macintosh/">Gimp under MacOS</a>. Still excellent tools. But she needs more precision and bought the Magic mouse which she&#8217;s not very satisfied with. You can change the acceleration but not the speed. Annoying. OpenOffice also works like a charm on MacOS.</p>
<p>As for me I really &#8211; really &#8211; miss a decent keyboard with keys as delete, home, end, page up and page down. I didn&#8217;t expect them to be missing from the Macbook keyboard. In time I guess I&#8217;ll get use to the weird key combinations that is needed to replace them. I might even get used to the weird combinations needed to write backspace, brackets and curly braces. But the keyboard is not really designed for programmers. On the other hand the multitouch trackpad is great. Virtual desktops in MacOS is also a bit limited but it&#8217;s not a big issue. All in all I&#8217;m slowly getting used to the hardware and the way things work under MacOS.</p>
<p>However, MacOS is not enough. There are PHP distributions for Mac. But as I use Ubuntu in production I use Virtualbox to run a 32-bit Ubuntu in a virtual machine. After disabling the Intel VT-x CPU optimization the 32-bit Ubuntu runs as smooth as ever. For some reason Virtualbox refuse to disable VT-x for Ubuntu 64-bit which is the reason I have to use 32-bit. With the VT-x (optimization) enabled the virtual machine with Ubuntu freeze for a couple of seconds every five seconds or so. I work in many different places, in different wireless networks and often using 3G. To make it work in any network I&#8217;m connected to I needed to setup two network adapters for the guest OS. One network adapter to allow the guest OS reach the outside world and another for communication between the host OS and the guest. I also have Virtualbox running a windows installation to allow me easy testing in a windows environment without hassle.</p>
<p>When buying Macbooks I also decided to buy Zend Studio for MacOS. I haven&#8217;t looked back once to either PDT or emacs. It is a great feeling being able to use subversion, debug, refactor, run tests and much more in the same editor without setting things up and tweaking PDT. It just works. I&#8217;m happy with it. Let&#8217;s me focus on development. And it is not as slow as for example SpringSource Tool Suite for java development. The workspace with the projects I work on I have in a shared directory accessible to both MacOS and the Ubuntu virtual machine.</p>
<p>In addition I use <a href="http://wb.mysql.com/">MySQL Workbench</a> a lot. It is also available for MacOS. It is a great tool for designing and working with MySQL databases. I still use the command line a lot as I&#8217;ve done since 1997 when I first started working with MySQL. But with just a few clicks the Workbench let me see changes between a database and the schema, export all the changes to a database in development, staging and finally production. (I always use an ssh tunnel to push schema changes to staging and production databases as I never allow ftp or anything else.) I still run the MySQL development databases on the virtual machine though.</p>
<p><a href="http://www.omnigroup.com/products/omnigraffle/">OmniGraffle</a> is another application I decided to buy. I use it to create diagrams and flowcharts but also to build graphical user interfaces. Especially when designing iPhone apps. Great tool and well worth the money. You can find stencils for most purposes at <a href="http://graffletopia.com/">Graffletopia</a>.</p>
<p>Even though we still use mostly open source software, compared to a linux environment, the move to Macbook cost a lot. Especially for a small company as ours. But after a few months I still think it&#8217;s worth the money. The actual hardware is great. Looks good. Silent although it does get a bit too hot underneath. The high resolution anti-glare screen is fantastic. I can even work in direct sunlight outdoors. I never want to see another crappy Sony Vaio. If only my Macbook could stop crashing every now and then I&#8217;d be really satisfied.</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/2011/07/php-development-on-mac-my-experience/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/2011/07/php-development-on-mac-my-experience/&amp;title=PHP+development+on+Mac+-+my+experience" 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/2011/07/php-development-on-mac-my-experience/&amp;t=PHP+development+on+Mac+-+my+experience" 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/2011/07/php-development-on-mac-my-experience/&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/2011/07/php-development-on-mac-my-experience/&amp;title=PHP+development+on+Mac+-+my+experience&amp;summary=A%20while%20ago%20I%20saw%20a%20lot%20of%20people%20writing%20about%20their%20PHP%20development%20environment%20and%20tools.%20I%20didn%27t%20get%20around%20to%20it%20at%20the%20time%20but%20yesterday%20I%20found%20me%20some%20time%20to%20write%20down%20my%20experiences%20of%20moving%20from%20Linux%20to%20MacOS%20X%20as%20primary%20OS%20for%20PHP%20%C2%A0and%20web%20development%0D%0A%0D%0AMe%20and%20my%20partner%20in%20Dotvo&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/2011/07/php-development-on-mac-my-experience/" 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/2011/07/php-development-on-mac-my-experience/&amp;title=PHP+development+on+Mac+-+my+experience" 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=PHP+development+on+Mac+-+my+experience+-+http://bit.ly/j4A2iK&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/2011/07/php-development-on-mac-my-experience/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>The MongoDB vs MySQL debate&#8230;</title>
		<link>http://www.dotvoid.com/2010/09/the-mongodb-vs-mysql-debate/</link>
		<comments>http://www.dotvoid.com/2010/09/the-mongodb-vs-mysql-debate/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 06:36:10 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nosql]]></category>

		<guid isPermaLink="false">http://www.dotvoid.com/?p=456</guid>
		<description><![CDATA[
Same stupid debate as so often before. Just the topics are different from time to time. Found via the Swedish Utvbloggen, RWW, highscalability och myNoSQL.




		
			Subscribe to the comments for this post?
		
		
			Share this on del.icio.us
		
		
			Share this on Facebook
		
		
			Post on Google Buzz
		
		
			Share this on LinkedIn
		
		
			Share this on Plaxo
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Tweet This!
		




]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="390" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="height=390&amp;width=480&amp;file=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_web_finallo-flv.flv&amp;image=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_poster.jpg&amp;link=http://www.xtranormal.com/watch/6995033&amp;searchbar=false&amp;autostart=false" /><param name="src" value="http://www.xtranormal.com/site_media/players/jwplayer.swf" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="390" src="http://www.xtranormal.com/site_media/players/jwplayer.swf" flashvars="height=390&amp;width=480&amp;file=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_web_finallo-flv.flv&amp;image=http://newvideos.xtranormal.com/web_final_lo/574b3910-afc9-11df-914b-003048d69c21_27_web_final_lo_poster.jpg&amp;link=http://www.xtranormal.com/watch/6995033&amp;searchbar=false&amp;autostart=false" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Same stupid debate as so often before. Just the topics are different from time to time. <em>Found via the Swedish <a href="http://utvbloggen.se/nosql-humor-med-mongodb-vs-mysql/">Utvbloggen</a>, <a href="http://www.readwriteweb.com/cloud/2010/09/an-amusing-take-mysql-diehard.php">RWW</a>, <a href="http://highscalability.com/blog/2010/9/5/hilarious-video-relational-database-vs-nosql-fanbois.html">highscalability </a>och <a href="http://nosql.mypopescu.com/post/1016320617/mongodb-is-web-scale">myNoSQL</a></em>.</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/2010/09/the-mongodb-vs-mysql-debate/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/2010/09/the-mongodb-vs-mysql-debate/&amp;title=The+MongoDB+vs+MySQL+debate..." 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/2010/09/the-mongodb-vs-mysql-debate/&amp;t=The+MongoDB+vs+MySQL+debate..." 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/2010/09/the-mongodb-vs-mysql-debate/&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/2010/09/the-mongodb-vs-mysql-debate/&amp;title=The+MongoDB+vs+MySQL+debate...&amp;summary=%0D%0A%0D%0ASame%20stupid%20debate%20as%20so%20often%20before.%20Just%20the%20topics%20are%20different%20from%20time%20to%20time.%20Found%20via%20the%20Swedish%20Utvbloggen%2C%20RWW%2C%C2%A0highscalability%20och%C2%A0myNoSQL.&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/2010/09/the-mongodb-vs-mysql-debate/" 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/2010/09/the-mongodb-vs-mysql-debate/&amp;title=The+MongoDB+vs+MySQL+debate..." 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=The+MongoDB+vs+MySQL+debate...+-+http://b2l.me/ap74me&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/2010/09/the-mongodb-vs-mysql-debate/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Reordering nested sets using PHP and Javascript</title>
		<link>http://www.dotvoid.com/2007/09/reordering-nested-sets-using-php-and-javascript/</link>
		<comments>http://www.dotvoid.com/2007/09/reordering-nested-sets-using-php-and-javascript/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 10:29:47 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=235</guid>
		<description><![CDATA[The adjancency method
Representing a tree of nodes, for example product categories, in a relational database is not hard. The most common way of doing it is to store a parentid with each node. This is also known as the adjacency list model. It is sometimes also referred to as the recursive model. Whatever the name [...]]]></description>
			<content:encoded><![CDATA[<h3>The adjancency method</h3>
<p>Representing a tree of nodes, for example product categories, in a relational database is not hard. The most common way of doing it is to store a parentid with each node. This is also known as the adjacency list model. It is sometimes also referred to as the recursive model. Whatever the name it is easy to grasp. It is very simple to insert and move nodes around but it is not an optimal solution if you often select the whole tree from the database for displaying on a web page as you need to recursively select all children of nodes.</p>
<h3>The nested set model</h3>
<p>A much better solution is the nested set model. In this model trees are represented as nested sets. Instead of using a parentid you have a left and right value for each node expressing the relationship to other nodes. A tree of nodes can look like this.</p>
<pre>        34
         |
         +--36
         |   |
         |   +--46
         |   |
         |   +--47
         |
         +--38
             |
            +--39</pre>
<p>The same data can be viewed more graphically as nested sets. This is also the way they are stored in the database. Notice how the left and right values are numbered in order from the outermost left to the outermost right.</p>
<pre>                            id:34
   +----------------------------------------------------+
   |             id:36                     id:38        |
   |   +------------------------+    +--------------+   |
   |   |    id:46      id:47    |    |     id:39    |   |
   |   |   +-----+    +-----+   |    |   +------+   |   |
  1|  2|  3|     |4  5|     |6  |7  8|  9|      |10 |11 |12
   |   |   +-----+    +-----+   |    |   +------+   |   |
   |   +------------------------+    +--------------+   |
   +----------------------------------------------------+</pre>
<p>In the database this is stored as in the following table.</p>
<pre> +----+-----+-----+
 | id | lft | rgt |
 +----+-----+-----+
 | 34 | 1   | 12  |
 | 36 | 2   |  7  |
 | 46 | 3   |  4  |
 | 47 | 5   |  6  |
 | 38 | 8   | 11  |
 | 39 | 9   | 10  |
 +----+-----+-----+</pre>
<p>This allow you to select the full tree with only one select statement. Normally you select the full list of nodes including the depth of each node as shown below in the small table containing id and depth. It is then easy to loop over the data in PHP to produce a nice tree in HTML/CSS.</p>
<p>The data below can be displayed as the the tree on right. The depth is in parenthesis.</p>
<pre> +----+-------+        34 (0)
 | id | depth |         |
 +----+-------+         +--36 (1)
 | 34 | 0     |         |   | 
 | 36 | 1     |         |   +--46 (2)
 | 46 | 2     |         |   |
 | 47 | 2     |         |   +--47 (2)
 | 38 | 1     |         |
 | 39 | 2     |         +--38 (1)
 +----+-------+             |
                            +--39 (2)</pre>
<p>Here is a more thorough article on <a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html">how you use MySQL with nested sets</a>.</p>
<h3>On to the problem</h3>
<p>Last night I was working on an application that display a full tree where the user must be able to to drag and drop nodes to reorder the tree. The problem is that it is much more difficult to insert or reorder the tree using the nested set model.</p>
<p>For the actual html I produced nested ordered lists using the OL and LI html element so that it was easy to use with the excellent <a href="http://youmuppet.com/?page_id=9">MooTree script</a> based on <a href="http://www.mootools.net/">MooTools</a>. (It does seem to have trouble with the latest version of MooTools though.) After reordering the structure it was easy to extract the tree list including the depth of each node. I sent this to the PHP backend to be handled there. The text data I sent to the PHP backend then look like below.</p>
<pre> 34,0
 36,1
 46,2
 47,2
 38,1
 39,2</pre>
<p>As you can see it looks exactly like the data I selected from the database previously. So I had to create a function in PHP that took this indata and produced a list of nodes with the correct left and right values. This list is then looped over to update all the nodes in the database.</p>
<pre>function depth2nestedset($data)
{
  $lines = explode("\n", $data);
  $rows = array();
  $stack = array();

  $lft = 0;   // Left value
  $rgt = 0;   // Right value
  $plvl = -1; // Previous node level

  foreach($lines as $line) {
    list($id, $lvl) = explode(',', $line);

    // Skip empty/faulty lines
    if (trim($id) == '') {
      continue();
    }

    if ($lvl &gt; $plvl) {
      $lft++;
      $rgt = 0;
      array_push($stack, $id);
    }
    else if ($lvl == $plvl) {
      $pid = array_pop($stack);
      $rows[$pid][2] = $rows[$pid][1] + 1;
      $lft = $lft + 2;
      $rgt = 0;
      array_push($stack, $id);
    }
    else {
      $lft = $lft + ($plvl - $lvl) + 2;

      $diff = $plvl - $lvl + 1;
      for($n = 0; $n &lt; $diff; $n++) {
        $pid = array_pop($stack);
        $rows[$pid][2] = $lft - $diff + $n;
      }
      array_push($stack, $id);
    }

    $rows[$id] = array($id, $lft, $rgt);
    $plvl = $lvl;
  }

  $plvl++;
  $cnt = count($rows) * 2;
  $leftovers = count($stack);

  for($n = 0; $n &lt; $leftovers; $n++) {
    $pid = array_pop($stack);
    $rows[$pid][2] = $cnt - $plvl-- + $n;
  }

  return $rows;
}</pre>
<p>The resulting associated array that is returned looks like below.</p>
<pre>Array
(
    [34] =&gt; Array
        (
            [0] =&gt; 34
            [1] =&gt; 1
            [2] =&gt; 12
        )
    [36] =&gt; Array
        (
            [0] =&gt; 36
            [1] =&gt; 2
            [2] =&gt; 7
        )
    [46] =&gt; Array
        (
            [0] =&gt; 46
            [1] =&gt; 3
            [2] =&gt; 4
        )
    [47] =&gt; Array
        (
            [0] =&gt; 47
            [1] =&gt; 5
            [2] =&gt; 6
        )
    [38] =&gt; Array
        (
            [0] =&gt; 38
            [1] =&gt; 8
            [2] =&gt; 11
        )
    [39] =&gt; Array
        (
            [0] =&gt; 39
            [1] =&gt; 9
            [2] =&gt; 10
        )
)</pre>
<p>That makes the circle complete. From left/right values in the database to a node tree based on depths that is easy to manipulate in html and then back to left/right values. Hopefully this makes sense. Do you have a better solution or more examples on applications that do this I would love to hear about it.</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/2007/09/reordering-nested-sets-using-php-and-javascript/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/2007/09/reordering-nested-sets-using-php-and-javascript/&amp;title=Reordering+nested+sets+using+PHP+and+Javascript" 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/2007/09/reordering-nested-sets-using-php-and-javascript/&amp;t=Reordering+nested+sets+using+PHP+and+Javascript" 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/2007/09/reordering-nested-sets-using-php-and-javascript/&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/2007/09/reordering-nested-sets-using-php-and-javascript/&amp;title=Reordering+nested+sets+using+PHP+and+Javascript&amp;summary=The%20adjancency%20method%0D%0ARepresenting%20a%20tree%20of%20nodes%2C%20for%20example%20product%20categories%2C%20in%20a%20relational%20database%20is%20not%20hard.%20The%20most%20common%20way%20of%20doing%20it%20is%20to%20store%20a%20parentid%20with%20each%20node.%20This%20is%20also%20known%20as%20the%20adjacency%20list%20model.%20It%20is%20sometimes%20also%20referred%20to%20as%20the%20recursive%20model.%20W&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/2007/09/reordering-nested-sets-using-php-and-javascript/" 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/2007/09/reordering-nested-sets-using-php-and-javascript/&amp;title=Reordering+nested+sets+using+PHP+and+Javascript" 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=Reordering+nested+sets+using+PHP+and+Javascript+-+http://b2l.me/wt8gN&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/2007/09/reordering-nested-sets-using-php-and-javascript/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The nested set model &#8211; hierarchical data in MySQL</title>
		<link>http://www.dotvoid.com/2007/03/the-nested-set-model-hierarchical-data-in-mysql/</link>
		<comments>http://www.dotvoid.com/2007/03/the-nested-set-model-hierarchical-data-in-mysql/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 23:20:48 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=216</guid>
		<description><![CDATA[I&#8217;m working on a small PHP project handling data which is organized in a hierarchical fashion. This is a common task and I have done it before creating forums and the like. This time no different than any other I was swearing over the rather ugly and most of all inefficient code needed for fetching [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a small PHP project handling data which is organized in a hierarchical fashion. This is a common task and I have done it before creating forums and the like. This time no different than any other I was swearing over the rather ugly and most of all inefficient code needed for fetching a full hierarchy from the database and displaying it nicely. Vaguely I remembered reading something about a rather different approach.</p>
<p>Searching Google I finally found a <a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html">MySQL article on the nested set model</a> which is a lot more efficient. The algorigthm basically skips the whole parent/child relationship between nodes. Instead you work with what is best described as &#8220;neighbouring&#8221; nodes. This allows you to retrieve a fully ordered hierarchical tree, including the level/depth of each node in the tree, using only one simple sql statement.</p>
<p>Those that are not familiar with the nested set model should definitely read the article.</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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/&amp;title=The+nested+set+model+-+hierarchical+data+in+MySQL" 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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/&amp;t=The+nested+set+model+-+hierarchical+data+in+MySQL" 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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/&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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/&amp;title=The+nested+set+model+-+hierarchical+data+in+MySQL&amp;summary=I%27m%20working%20on%20a%20small%20PHP%20project%20handling%20data%20which%20is%20organized%20in%20a%20hierarchical%20fashion.%20This%20is%20a%20common%20task%20and%20I%20have%20done%20it%20before%20creating%20forums%20and%20the%20like.%20This%20time%20no%20different%20than%20any%20other%20I%20was%20swearing%20over%20the%20rather%20ugly%20and%20most%20of%20all%20inefficient%20code%20needed%20for%20fetching%20&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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/" 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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/&amp;title=The+nested+set+model+-+hierarchical+data+in+MySQL" 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=The+nested+set+model+-+hierarchical+data+in+MySQL+-+http://b2l.me/wttdk&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/2007/03/the-nested-set-model-hierarchical-data-in-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL 4, Apache 1.3 and PHP 4.3 on Solaris x86</title>
		<link>http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/</link>
		<comments>http://www.dotvoid.com/2004/09/mysql-4-apache-13-and-php-43-on-solaris-x86/#comments</comments>
		<pubDate>Thu, 02 Sep 2004 07:20:26 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=35</guid>
		<description><![CDATA[
Yesterday I decided it was time to get a proper PHP 4 environment configured on my new machine running the x86 version of Solaris 9. I know going outside Windows or Linux with PHP sometimes can be tricky. I haven&#8217;t used PHP on Solaris since my time at AOL in Dublin three years ago, so I decided to write down exactly [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>Yesterday I decided it was time to get a proper PHP 4 environment configured on my new machine running the x86 version of Solaris 9. I know going outside Windows or Linux with PHP sometimes can be tricky. I haven&#8217;t used PHP on Solaris since my time at AOL in Dublin three years ago, so I decided to write down exactly how, what and why I did things. I expected it to be a bit simpler then last time as I planned to use Apache rather than IPlanet (or whatever the name is today, it seems to change at least once a week). So my plan was to install a pretty standard LAMP environment. That is without the L ofcourse.</p></div>
<div class="itemview">
<h3>Preparations</h3>
<p>The first thing I had to do was to download the different GNU packages needed to compile MySQL, PHP and many other open source projects on Solaris. These packages can all be found on <a href="http://www.sunfreeware.com/">Sunfreeware.com</a>. The packages I installed, by default under /usr/local,  were:</p>
<ul>
<li>gcc</li>
<li>gmake</li>
<li>flex</li>
<li>bison</li>
<li>m4</li>
<li>autoconf</li>
<li>automake</li>
<li>gzip</li>
<li>tar</li>
<li>GNU sed</li>
<li>libiconv</li>
</ul>
<p>All packages are easy to install using <em>pkgadd</em>. Care needs to be taken to set the system paths correctly after the installation. I used the command <em>crle -u -l /usr/local/lib</em> to add the lib directory to the system defaults. Then I added <em>/usr/local/bin</em> first in my PATH to make sure GNU versions take precedence if there are any conflicts. For example the package m4 could be found on the system already. I also appended <em>/usr/ccs/bin</em> last to the PATH as there are programs there needed for compilation and linking.</p>
<h3>MySQL</h3>
<p>Having the environment setup as I wanted it I set my eyes on installing MySQL. I couldn&#8217;t find an official binary package for Solaris 9 x86 so I had to build it myself. I downloaded the source from <a href="http://www.mysql.com/">mysql.com</a>, quickly unpacked it and failed miserably at compiling it.</p>
<p>A quick research using Google gave me <a href="http://forum.sun.com/thread.jsp?forum=11&amp;thread=20228">the answer</a>. The command <span style="font-style: italic;">mkheaders</span> refused due to paths not being found. So additionally I had to create a softlink as the paths for some reason differed. After creating the symlink I could generate the gcc header files. The exact commands issued are as below.</p>
<pre># ln -s /usr/local/lib/gcc /usr/local/lib/gcc-lib
# cd /usr/local/libexec/gcc/i386-pc-solaris2.9/\
  3.4.1/install-tools
# ./mkheaders</pre>
<p>Then I tried compiling MySQL again. This time, everything could be done by the book. For sake of convenience &#8211; here&#8217;s a near copy from the MySQL manual.</p>
<pre># ./configure --prefix=/usr/local/mysql
# make &amp;&amp; make install
# cp support-files/my-medium.cnf /etc/my.cnf</pre>
<pre># cd /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .</pre>
<p>The only thing left then is to start the MySQL daemon and set the root password.</p>
<pre># bin/mysqld_safe --user=mysql
# bin/mysqladmin -u root password XXXXXX
# bin/mysqladmin -u root -h myhost password XXXXXX</pre>
<h3>Installing gd</h3>
<p>I need gd for, among other things, thumbnail generation. As I wanted to download and compile as little as possible a quick check revealed that freetype, libjpeg, libpng and libiconv already existed in my default Solaris 9 installation. The libraries can be found under the <em>/usr/sfw</em> directory.</p>
<p>I wanted the newest version of gd as GIF support is now added again after being removed for several years due to Unisys suddenly starting do demand licensing fees for their LZW patent a few years ago. So I could not use the slightly older gd available as a package at sunfreeware.</p>
<p>I downloaded version 2.0.28 and tried to compile it. However, I could not get it to compile using the libiconv already installed. Instead I had to download libiconv from sunfreeware and install it under <em>/usr/local</em>. The following configure command was what I ended up with to get gd to compile.</p>
<pre># ./configure \
  --prefix=/usr/local \
  --with-freetype=/usr/sfw \
  --with-png=/usr/sfw \
  --with-jpeg=/usr/sfw \
  --with-libiconv-prefix=/usr/local</pre>
<p>After that compiling the package was a breeze.</p>
<pre># make &amp;&amp; make install</pre>
<h3>On to apache</h3>
<p>Apache must be the easiest application around to build on different platforms. I have never experienced any problems building a stable apache release on any unix platform. I did once have problems getting it to run on NT 4 when the windows version still was marked unstable. I guess that could be expected though. So creating a standard build of apache is very straight forward.</p>
<pre># ./configure --prefix=/usr/local/apache-1.3.31 \
  --enable-module=so
# make &amp;&amp; make install</pre>
<h3>PHP &#8211; finally</h3>
<p>Compiling PHP became, as it turned out, a bit tricky becaused of my decision to enable gd support. The reason was that the PHP configure script didn&#8217;t list libiconv when checking that all the gd functions were correct. The configure script just said &#8220;no&#8221; to all the gd functions and refused to create the makefiles. After awhile I looked through the generated config.log. This revealed that what really failed was not actually gd. When loading gd to check what functions were available it failed to find symbols from libiconv. This must either be a bug in the configure script or more probable a problem with my Solaris 9 environment and the library paths.</p>
<p>So prior to running the configure script I had to manually amend the configure script and add <em>-liconv</em> in all places where <em>-lgd</em> could be found. That did the trick and the script happily trotted along as it should.</p>
<pre># ./configure \
  --with-apxs=/usr/local/apache-1.3.31/bin/apxs \
  --with-mysql=/usr/local/mysql/ \
  --with-gd=/usr/local \
  --with-freetype-dir=/usr/sfw \
  --enable-gd-native-ttf \
  --with-png-dir=/usr/sfw \
  --with-zlib-dir=/usr/sfw \
  --with-jpeg-dir=/usr/sfw</pre>
<pre># make &amp;&amp; make install</pre>
<p>After that I added the directives needed in httpd.conf to enable PHP4. Actually I only had to add the second line below as the LoadModule directive was already present.</p>
<pre>LoadModule php4_module libexec/libphp4.so
AddType application/x-httpd-php .php</pre>
<p>And finally, at 03:43 AM, I could verify the installation and configuration using the simple php script with a call to phpinfo(). Of course it worked like a charm.</p>
<p>All that remains now is to get Apache 2 and PHP 5 up and running alongside. I still haven&#8217;t figured out if the good PHP folks recommend Apache 2 for production yet. Anyways,<br />
that&#8217;ll be a project for another night.</p></div>


<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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;title=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86" 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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;t=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86" 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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;title=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86&amp;summary=%0D%0A%0D%0AYesterday%20I%20decided%20it%20was%20time%20to%20get%20a%20proper%20PHP%204%C2%A0environment%20configured%20on%20my%20new%20machine%C2%A0running%C2%A0the%C2%A0x86%20version%20of%20Solaris%209.%C2%A0I%20know%20going%20outside%20Windows%20or%20Linux%20with%20PHP%20sometimes%C2%A0can%20be%20tricky.%20I%20haven%27t%20used%20PHP%20on%20Solaris%20since%20my%20time%20at%20AOL%20in%20Dublin%20three%20years%20ago%2C%20so%20I%20de&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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/" 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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/&amp;title=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86" 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=MySQL+4%2C+Apache+1.3+and+PHP+4.3+on+Solaris+x86+-+http://b2l.me/w7g6z&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/09/mysql-4-apache-13-and-php-43-on-solaris-x86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP5 Overview</title>
		<link>http://www.dotvoid.com/2003/11/php5-overview/</link>
		<comments>http://www.dotvoid.com/2003/11/php5-overview/#comments</comments>
		<pubDate>Sun, 09 Nov 2003 22:47:06 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pdo]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.commodi.com/?p=27</guid>
		<description><![CDATA[
PHP5 is still far from being finished even though you can already download a beta version. The performance improvements, the better object orientation and XML support, the new PDO extension and many other small and large changes make many of us wish it was already here. After attending the PHP Conference 2003 in Frankfurt I [...]]]></description>
			<content:encoded><![CDATA[<div class="preamble">
<p>PHP5 is still far from being finished even though you can already download a beta version. The performance improvements, the better object orientation and XML support, the new PDO extension and many other small and large changes make many of us wish it was already here. After attending the PHP Conference 2003 in Frankfurt I wrote this article to give you an overview of the major changes in PHP5 from PHP4 and what to expect when porting old applications.</p></div>
<h3>General improvements</h3>
<p><strong>Performance</strong></p>
<p>PHP5 will generally be a lot faster than PHP4. Primarily, the execution model have been changed from PHP4. A php script is compiled into arrays of op codes before it is executed. PHP4 essentially use a big switch statement when executing operations from these arrays. PHP5 use function pointers and hash table lookups for function pointers are cached. Just calling PHP functions should be around 40% faster. Algorithms for comparisons have also been reworked and they should now be much more efficient.</p>
<p><strong>Constants</strong></p>
<p>Real constants are finally being introduced. Earlier define() was used for declaring constants. This was slow since it was actually a function call and resolved at runtime. This wouldn’t matter too much if it wasn’t for the fact that defines are used by many projects for storing translations of strings. It might even be the most common form of providing translations in PHP projects. Constants on the other hand are resolved at compile time. So as in most other programming languages the constants in the code will actually be replaced with the value it represents before execution.</p>
<h3>XML support</h3>
<p><strong>Small revolution</strong></p>
<p>The other area that is close to a revolution is the improved xml support in PHP5. As many other things, xml support in PHP4, was really just a big hack and squeezed in without much thought. Both the DOM and the XSLT extensions were marked as being experimental and they had many problems. SAX on the other hand worked pretty good but is a mess to work with. You have to write a lot of code to do very little xml parsing.</p>
<p>All the new xml extensions use libxml and libxslt which means expat and sablotron are being dropped. Libxml is one of the fastest implementations available and have very good support for the standards. The xml extensions in PHP5 are xml, dom, simplexml, xsl and soap. The xml, dom and simplexml extensions will most likely be compiled in as default which should improve xml support in hosting environments. The xml extension support loading of non wellformed html documents and most dom level 2 methods are implemented.</p>
<p>In PHP5 both the XSL and DOM extensions are new. The XSLT extension is called ext/xsl. The reason for it to be called xsl is to allow the old ext/xslt extension to stay for those who wish to use it. It should be noted however that libxslt is much faster than sablotron, which is used by the old xslt extension. The xsl api methods are derived from api methods in the mozilla implementation.</p>
<p><strong>Problematic error handling</strong></p>
<p>There is a problem with the error handling though. The dom methods throws exceptions where the dom standard so requires. In some other circumstances old type PHP errors will be produced. This mix of error handling methods is a bit confusing and hopefully this will be fixed by the time PHP5 is ready. Some dom methods are not completely ready. The method getElementsByTagName() currently returns an array which is not correct. This will change so that a real nodelist is returned instead.</p>
<p><strong>Interoperability</strong></p>
<p>All the xml extensions are now compeletely interoparable. They all load xml and create DOM trees in memory. This dom tree can then be shared and passed around between the different xml extensions. The best about this is that you can load an xml document into memory, use dom methods and xpath expressions to locate data and change it in memory, and then finally load a xsl template into it’s own dom tree and apply it on the original dom tree. You might not even have to load the xsl template since you could have it cached in shared memory from a previous request. The ability to cache dom trees in memory should give you a huge performance increase.</p>
<p><strong>SimpleXML</strong></p>
<p>This is all good and well. But the best part is yet to come – simpleXML. This new extension written by Sterling Hughes makes it so easy to work with xml data that, as he put it, any monkey with enough bananas can do it. I am inclined to agree with him. As with all the other xml extensions simpleXML integrate nicely with the others. What it do is enable you to work on xml documents as they were native PHP structures of associative arrays. A simple code example below loads a xml file with a booklist and displays the titles of the books. All in just five lines of code.</p>
<pre><code>&lt;?php
$booklist = simplexml_load_file(‘mybookfile’);
foreach ($booklist-&gt;book as $book) {
	echo $book-&gt;title .”n”;
}
?&gt;</code></pre>
<p>It can hardly be simpler. The extension allows you to convert back and forth between simple xml and a dom tree. You can instead of reading it from a file load the xml from a database and use the function simplexml_load_string(). Some design decisions made for simpleXML, to make it this simple, can make it weird to work with though. Node attributes are for example treated as just another level of nodes.</p>
<p><strong>More advanced XML</strong></p>
<p>Through the use of libxml PHP5 will support validation of xml documents against DTD, XML Schema and the simpler, independent standard, RelaxNG. Schema support in libxml is still not there to 100%. All basic things should be supported however. Validation of the xml is an important feature since you can be confident that when you are working on a dom tree that the data in it is syntactically correct. This is especially important when you start working with SOAP.</p>
<p>Unfortunately SOAP support is currently not finalized and yet to be added to PHP5. What is clear though is that SOAP will be supported natively by PHP5. Right now the options are to use either nuSOAP, the smaller but faster soap extension available through PECL or any other of the numerous PHP implementations available. NuSOAP gives you the ability to create WSDL specification programmatically through the use of a set of api methods. The PECL soap extension is however a faster choice since it does not have the overhead of loading the rather large NuSOAP class file written in PHP.</p>
<p>The xml extensions will also support PHP streams. Using the stream support you can register your own stream handlers. Supported out of the box are php, http, https, ftp, ftps and compress.bz2. One example of using your own stream handlers is in conjunction with xinclude to dynamically change the content of a static xml document.</p>
<h3>Database support</h3>
<p><strong>The new PDO extension</strong></p>
<p>This is another area that is getting a big makeover. There is a new extension called PDO, PHP Data Objects. Obviously enough for anyone is that it is derived from the name ADO. It is not, however, something that is supposed to look like ADO or work in the same fashion.</p>
<p>The pdo extensions give you database abstraction on the function layer and provides a uniform way of connecting to and using databases from different vendors. This is ofcourse a huge leap forward from the mess in PHP4 with all the different extensions for each database with different naming and parameter conventions.</p>
<p><strong>More choice</strong></p>
<p>The extension provides several new ways of sending queries to a database. It supports unbuffered queries where only a result handle is returned from the database. Unbuffered queries also support destructive reads. Using this feature means that data, as soon as you use it, will be destroyed in the engine. In other words, you cannot go back and reread the data returned in a result set. This is said to improve speed somewhere between 50 – 70% over buffered non desctructive reads.</p>
<p>You will still have the option of fetching rows in associative arrays or regular arrays. As associative arrays are much more expensive to create performancewise, the default returned will be numerical arrays. Several other query functions are also created to increase speed in certain circumstances. One method will allow you to send a query and directly get the whole result returned as a normal PHP structure. Yet another is the fastest choice when you only return one column.</p>
<p>A weird but neat feature is that you can query the database and at the same time provide a class. An object will automatically be intantiated and initialized with the values from the database.</p>
<p><strong>Iterators</strong></p>
<p>Using iterators, that also are new for PHP5, allow you to loop over a resultset without doing so explicitly in your PHP code. You could do this previously using arrays and a foreach loop. The foreach loop is extended to work with objects now. Since the looping is done internally in the PHP core it will be much faster.</p>
<p>The consensus is that with the pdo extension you will have more options than before and a greater opportunity to profile your code for speed.</p>
<h3>Mysql support</h3>
<p><strong>Mysqli and PDO</strong></p>
<p>Work on PDO, described above, was started quite recently. The need for better database api’s however was recognized a long time ago. MySQL have evolved during the years and is now a very mature database management system featuring transactions, sub queries, replication and many other things. Views and foreign keys are still not there but is slowly in the making. Foreign keys can even be tested in the early versions of MySQL 5.0. The mysql extension have on the other hand not evolved much. The api does not closely follow the C api and many things are missing. Because there are optional parameters to many mysql functions it is also hard to add parameters to functions without breaking backwards compatibility.</p>
<p>Therefore work started on a brand new mysqli extension. This api match the C api much more closely and supports the MySQL 4.1 api. It is not 100% backwards compatible. Since the old mysql extension will stick around for some time this should not be a major problem. It is more than likely that some PHP installations will have both extensions enabled at the same time, allowing both old and new applications to work.</p>
<p><strong>Prepared SQL statements</strong></p>
<p>New for mysqli is support for preparing SQL statements which let the MySQL engine compile them before you use them. If you use the same query several times with different data this will give you significant speed improvements over sending the full SQL statement every time. Since you supply the data together with a resource handle to the compiled query instead of a full SQL statement you will no longer have to bother about magic quotes and addslashes. The extension will take care about that for you. You should then obviously have magic_quotes_gpc set to off. You can ofcourse still send the whole statement at once exactly as before. However, when including large chunks of text or blobs that exceeds the maximum packet size allowed you should use prepared insert statements.</p>
<p>Currently it is not possible to store prepared SQL statements between requests. Zak Greant promised to look into this later as it would be very beneficial performancewise.</p>
<p><strong>Encryption of passwords</strong></p>
<p>One thing that might give some applications trouble is that MySQL have stopped using the old password crypto in favour of SHA-1. This is ofcourse much safer, providing 40 bit oneway encryption of passwords. Applications that use PHP functions to encrypt passwords using either SHA1 or md5 are not affected since this is on the MySQL side.</p>
<h3>What now?</h3>
<p>PHP5 have recently released a beta 2. It should probably not be considered as beta quality though. Most of the new features have been implemented already. Only five or six people are still in the business of discussing new or changing features for PHP5.</p>
<p>So it is not really beta quality. It is however stable enough to download, install and tinker with. For those of you who wants to be prepared it is probably time to start working on PHP5 support for your applications. There are enough changes in PHP5 that it might not be wise to trust it to be fully backwards compatible. We now know for a fact that it won&#8217;t.</p>
<p>At the conference both Sterling Hughes and Markus Börger answered the question &#8211; when? The optimistic Börger said March 2004 and the more pessimistic Hughes thought summer was more realistic.</p>
<h3>Object oriented support</h3>
<p><strong>Hybrid language</strong></p>
<p>Object orientation is one of the areas that is really changing in PHP5. Whereas there was only rudimentary support for object orientation before, PHP5 now implements most features required by OO purists. PHP will ofcourse be a hybrid language and apart from a few areas you can still ignore the object orientation and code procedural if that is your cup of tea. The fact remains that PHP is becoming a more object oriented language.</p>
<p><strong>Changes in PHP5</strong></p>
<p>One major change, that probably will decrease the bug count significantly in any project using classes and objects, is that objects are now sent by reference instead of by value as the default behaviour. You will no longer have to make sure you use ampersands at the right places. PHP5 have a reference count that keep track of the object usage. Objects will be freed when the reference count reaches zero, either by using unset() or by going out of scope.</p>
<p>A quick list of what object orientation in PHP5 introduces:</p>
<ul>
<li>Support for visibility, private, protected and public. You need to declare this for each property and method which is different from for example C++. If these keywords are omitted the default is public.</li>
<li>Objects are now referenced by identifiers, or resource handlers, that really just are integers. You will have to use a copy constructor, or rather the __clone() method to obtain an actual copy.</li>
<li>Constructor and destructor methods. The constructor can be parameterized but it seems there will be no support for several different constructors which is a big loss if you ask me. So the trick where you have several optional parameters and then count the number of parameters actually sent will still have to do &#8211; with all it’s drawbacks.</li>
<li>Static members and methods. Class properties and methods that all objects of a class share. A weird behaviour right now is that you can call non static methods without instantiating an object. This will hopefully change.</li>
<li>Interfaces allow classes to present themselves to the outside world and guarantees that a subclass implements all methods.</li>
<li>Abstract classes, property members and methods that enforces you to implement them in subclasses.</li>
<li>Final declaration allows you to stop further inheritance.</li>
<li>Interceptors that allow you to initialize data when you need it. This is used in lazy initialization for example in database calls.</li>
<li>Reflection API that helps you document your code.</li>
<li>Default member property values. That you set even before the constructor is called.</li>
<li>New PHP constants including __CLASS__ and __METHOD__. Both are evaluated at compile time. The first constant contain the class name and the latter evaluates to both the class name and the method name. If __METHOD__ is used outside of a class it evaluates to the current function.</li>
</ul>
<p><strong>Handling the memory</strong></p>
<p>To destruct an object you call unset. The function unset only decreases the reference count and you cannot be 100% sure that the object will be destructed. PHP is a language where you should not have to care about the memory that much and it might be that destructors aren’t that a good idea in PHP.</p>
<p>Another big gotcha is that parent constructors and destructors must be called explicitly. This means that it is easier to make the code run faster. What might be thought of as being a bit inconsistent is that if you don’t have a constructor in the subclass the parent constructor will be called automatically.</p>
<p><strong>Structured programming</strong></p>
<p>Type hinting is also a step forward to a more structured programming model. This allows you to enforce that a parameter can only accept an object of a certain class. This is currently only planned to work with classes and objects – not on base types like strings and numbers.</p>
<p>The one new feature you cannot ignore is the introduction of try/catch error handling. The problem is that some extensions of PHP5 will use try/catch and others will stick to the old error handling where error codes are returned.</p>
<p>With the above new features it is possible to implement most design patterns, for example the common factory pattern and singleton pattern. If you take the singleton pattern for example. You can now ensure that only one object is created using static members and then overload the __clone() method and declare it as private.</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/2003/11/php5-overview/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/2003/11/php5-overview/&amp;title=PHP5+Overview" 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/2003/11/php5-overview/&amp;t=PHP5+Overview" 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/2003/11/php5-overview/&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/2003/11/php5-overview/&amp;title=PHP5+Overview&amp;summary=%0D%0A%0D%0APHP5%20is%20still%20far%20from%20being%20finished%20even%20though%20you%20can%20already%20download%20a%20beta%20version.%20The%20performance%20improvements%2C%20the%20better%20object%20orientation%20and%20XML%20support%2C%20the%20new%20PDO%20extension%20and%20many%20other%20small%20and%20large%20changes%20make%20many%20of%20us%20wish%20it%20was%20already%20here.%20After%20attending%20the%20PHP%20C&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/2003/11/php5-overview/" 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/2003/11/php5-overview/&amp;title=PHP5+Overview" 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=PHP5+Overview+-+File: /data/app/webapp/functions.php<br />Line: 66<br />Message: Duplicate entry 'wwhfS' 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/2003/11/php5-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

