I know how to chain class methods (with the \"return $this\" and all), but what i am trying to do is to chain them in a smart way, have a look at this:
$albu
You will probably need a method that kicks of the actual query while the methods like select and order_by just store the information up to that point.
You can make this implicit though if you implement the Iterator interface, and run the query the first time rewind or current got hit (think foreach), or the Countable, so result counts could be generated by calling count() with the object. I'm personally would not like to use a library built like this, i would much more likely appreciate an explicit call so i can see where the queries triggered to run.