NYCPHP Meetup

NYPHP.org

[nycphp-talk] ORM anyone?

Kenneth Downs ken at secdat.com
Tue Sep 11 16:27:37 EDT 2007


LK wrote:
> Hello,
>  
> Please help me in overcoming a mental block about this wonderful thing 
> called ORM.
>  
> By reading some examples on using ORM, such as setting up Author/Books 
> parent/child objects, I notice that each author and each book has to 
> be individually assigned in the PHP script and saved. This is what I 
> don't understand,
>  
> 1. if my database contains thousands of authors and 100's of thousands 
> of books, I have to 1) create each new object 2) assign each field 
> value to it and 3) save it, and do this for 100's of thousands of 
> records? Somehow that just does not make sense, since the records are 
> already in the database, why do I have to save(..) them again?

Are you asking if it is necessary to create code that reproduces each 
row in each table in the database?  If so, the answer is no, definitely not.

>  
> 2. If I have an existing database with 100's of thousands of rows 
> already populated, how does ORM know which record corresponds to which 
> php object? In other words, how do I just start using existing mysql 
> records as php objects?

Presumably the user has indicated which row they want, usually as a 
result of some search.  You then instantiate a new object and populate 
it with those rows.

>  
> 3. If an existing database has many relations between tables, how do I 
> form complex joins between them using ORM?

PHP is a record-oriented step-wise language.  It is good for writing 
programs with
loops and if-then and case and so forth.  It is not good at manipulating 
sets of table-based data.

For manipulating sets of table-based data we use SQL (at least I do).

As you may guess, I'm no fan of ORM.  The main reason is what I just 
said above.  OO code and table-based data are two very different beasts 
with very different natures.  ORM tries to make one look like the 
other.  Why would anybody want to do this?   Hell if I know.

That being said, there are plenty of "solutions" out there that try to 
get around this.  IMHO they are all Rube Goldberg machines.


>  
> Thanks for your response
>  
> Leo
>
> ------------------------------------------------------------------------
> Need a vacation? Get great deals to amazing places 
> <http://us.rd.yahoo.com/evt=48256/*http://travel.yahoo.com/;_ylc=X3oDMTFhN2hucjlpBF9TAzk3NDA3NTg5BHBvcwM1BHNlYwNncm91cHMEc2xrA2VtYWlsLW5jbQ-->on 
> Yahoo! Travel.
> ------------------------------------------------------------------------
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php


-- 
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com    www.andromeda-project.org
631-689-7200   Fax: 631-689-0527
cell: 631-379-0010

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070911/45c069aa/attachment.html>


More information about the talk mailing list