?
Solved

MySQL Object storage (Data Persistency)

Posted on 2005-03-10
5
Medium Priority
?
500 Views
Last Modified: 2013-11-15
Hi,

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 :)

Snyke
0
Comment
Question by:Snyke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
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.
0
 
LVL 1

Author Comment

by:Snyke
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...
0
 
LVL 25

Accepted Solution

by:
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?
0
 
LVL 11

Expert Comment

by:neester
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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