Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


MySQL Object storage (Data Persistency)

Posted on 2005-03-10
Medium Priority
Last Modified: 2013-11-15

my problem is that I often design my MySQL-Tables the exact same fashion I design my PHP-Classes  (the only difference being that the PHP-Classes also have specific functions while the Database only holds the data, and that pointers to other objects (in PHP) are numeric references to a Table Index in MySQL).
I some time back found a neat class in the PEAR library (DB_DataObject: http://pear.php.net/package/DB_DataObject ) but could not get it to work, and anyway it seems pretty an overkill for my small applications... I don't need class-factories, thousands of config-files and stuff like that. I need a fast little library with a class I can extend with my own classes so that I can dynamically load the data from the tables into my classes, then work on those classes and at a later moment, maybe save them back to the database.

Does anyone know such a class? It would really help me a lot :)

Question by:Snyke
  • 2
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13515912
I've run into this before and not found a solution. Although my classes usually have a 1:1 relation with a DB record, sometimes they don't, and I use a class to represent something that's expressed as multiple records in several tables without using yet more classes. I still have trouble with the whole OO vs relational models thing - I'd love to see a way of building a factory class that doesn't have to know about the internal structure of the objects it's creating.

Author Comment

ID: 13524876
I often have classes that represent Data-Objects, and an abstraction layer would be really wonderfull. PEAR::DB_DataObject would really be nice, but I can't get it to run and nobody on this board could tell me how to do it, so I'm asking for an alternative...
LVL 25

Accepted Solution

Marcus Bointon earned 500 total points
ID: 13534152
PEAR::DB_DataObject does look very nice, and it has better docs than most PEAR packages, however, I note that it still doesn't address my principal peeve.

Say I have a mailinglist object that has links to many subscriber objects. I want to create an instance of the mailinglist, and get an array of all the subscriber objects. If this is done in a typical object-clean way (just as PEAR::DB_DataObject does), you'll typically use 1 query for the mailing list info, and 1 for EACH subscriber. This is a killer - a mailing list with 10,000 subscribers would have to do 10,000 (expensive) database queries on top of the same number of (cheap) object instantiations! You can work around this by creating a factory class that does a single query that selects all the subscriber data, and then uses that info to create the array of objects directly. However, in order to avoid making more queries, it would have to be getting all the subscriber data and stuffing it into the subscriber objects, which means that the factory class needs insider knowledge of the subscriber object structure, so if I change my subscriber object, or its table definition, I have to change my factory too. It gets worse if the subscriber object contains other object references too.

I've never seen a clean, generic solution to this, and it's responsible for massive slowdowns in OO code all over the place. Should the factory be a subclass of the subscriber so it gets private access? Or perhaps implement multiple interfaces - one for a generic factory class, one for the subscriber class (or whichever class you're doing this for).

I've really not encountered alternatives to PEAR::DB_DataObject, especially ones that go quite so deep. Perhaps see if you can find something that's built on top of ADODB?
LVL 11

Expert Comment

ID: 15639939
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept Squinky's solution

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

- Neester -
EE Cleanup Volunteer

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
"Any files you do not have backed up in at least two [other] places are files you do not care about."
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question