Jump to content

Recommended Posts

Hi all

Just wanted to get some thoughts from those experienced with ORM. I've been looking at both Django and Rails a bit more recently with a view to getting ideas for a newspaper CMS I've been building, especially with regards to Django's automatically generated admin interface.

 

I know I could use Python and Django for what I'm doing, but there are many reasons why I want to stick with PHP...

 

The idea: I have a "manager" class which handles retrieval of records from a database table. I'd expect to have a 'find' method and a 'load' method. The find method would be concerned with finding multiple records where as a load would be concerned with returning a single record. The loader would return an object that could be accessed with 'save()', etc methods, the finder would return an object which would enable iteration through these sorts of objects.

 

Hope that makes sense, but examples of all:

 

<?php
$u = UserManager();
$records = $u->findAll("created_at > $sometimestamp");

while ($record = $records->next()) {
   echo $record->username . '<br />';
}

$user = $u->load(1); // load record 1
echo $user->username;
$user->username = 'test_person';
$user->save();

$user = $u->create();
$user->username = 'another';
$user->password = 'password';
$id = $user->save();

// etc
// etc
?>

 

my questions:

1, is there a better, cleaner way of implementing Row Data Gateway / Table Data Gateway in PHP, considering the handy features PHP lacks that Ruby/Python have?

2, does anyone have a clue what performance is like? Consider, for example, I want a list of 20 articles on a 'list' or 'archive' page, i'd need to run the 'manager' to get 20 results, each of which would in turn be represented by a new object?

 

Cheers

Mark

Link to comment
https://forums.phpfreaks.com/topic/106198-orm-performance/
Share on other sites

yeah i've taken a look at a few, but generally they look quite "excessive" whereas i suppose (although my description above probably doens't show it ha!) I need something very very basic that I can plug in easily and just keep adding functionality to along the way as I need it. I suppose also that it's a little exercise for me too to get something nice like this working myself, as the rest of my framework is custom code.

 

so i guess I'm just trying to find out how "expensive" it is to have each record represented by a CRUD-type object, each table represented by a "manager" object which can find rows and return these CRUD objects.

 

thanks for the suggestion though - if nothing else it'll perhaps give me a few ideas. I just love the way Django does it though - very powerful but incredibly simple.

Link to comment
https://forums.phpfreaks.com/topic/106198-orm-performance/#findComment-544752
Share on other sites

one possible way i've stumbled upon to get a collection of objects is possibly via the use of PHP5's object iterator:

 

http://uk3.php.net/manual/en/language.oop5.iterations.php

 

Which would allow me to effectively run a foreach on a resultset object to return CRUD objects one by one as required, without instantiating one for each result in advance.

Link to comment
https://forums.phpfreaks.com/topic/106198-orm-performance/#findComment-544769
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.