Outlet ORM

30 01 2009

If you’ve ever tried to use an ORM to create a data layer in PHP, then you know its not always as easy as it seems. Not to mention if you actually have to change a relationship, you could be digging through thousands of lines of code for days. Not anymore, a friend of mine has created Outlet ORM, although in its early versions it’s well worth taking the time to learn.

I think that he does a fantastic job of explaining outlet:

“Outlet is an open source object-to-relational mapping tool for PHP.

It differs from other orm solutions for php in that it provides transparent, unobtrusive persistence. It does not require your entity objects to implement any interfaces or extend some sort of base class. It is also very lightweight, only a handful of classes and tools.

It uses an approach similar to hibernate in java, using proxy objects that save the data behind the scenes.”

From my experience so far its a fantastic tool to work with in PHP, it has definitely made my work in PHP quicker and more organized by creating objects for my database calls. It also takes care of saving/updating/deleting items for me in one easy call, EVEN if they relate to something else and need to be deleted. Great tool, check it out at http://www.outlet-orm.org.

Advertisements




MySQL Subqueries

8 03 2006

Those of you who know me i’ve been working on a website lately for a brick company. http://www.beehivebrick.com to be exact. Things are going great with it, here is a bumb in the road that in encountered that i think might help out some other PHP and MySQL programmers.

If your like me, you dont keep up on the newest and best ways to do PHP or MySQL, so you probably dont know what versions are compatable with what. With MySQL i was doing something like this at home:

SELECT * FROM images WHERE imgID NOT IN (SELECT imageID FROM relation);
-The above worked great on my home box, with MySQL version 5.0.

On the clients webserver, Lunar Pages, it didnt work. So i started looking around at what i did wrong that might be a slight difference in different versions of MySQL, well it turns out that Lunar Pages is running MySQL 4.0.25, which in turn does not support subqueries. They didnt start supporting them until v4.1, which on my home machine i have 5.0.

Anyway, the nice thing about subquieries is that they are easier to read, and formulate. I didnt have to look up a tutorial to figure out the above SQL query, i just messed around for a little until it came out right. However, to convert that to a MySQL 4.0 or less standard, or even just convert it to a non-subquery you change it into this:

SELECT * FROM `images` LEFT JOIN relation on relation.imageID=imgID WHERE imageID IS NULL;

Wow, so thats kind of a mouth full compared to the subquery above. So in the end i guess that its safe to say, i like subqueries a lot more than i like joins. Of course that seem to be a regular occurance over here at my school anyway.