Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 832229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:19:49+00:00 2026-05-15T04:19:49+00:00

I am developing my own class model for my database and I would like

  • 0

I am developing my own class model for my database and I would like to know what you guys think of it.

For each table in my database I have 2 classes. The first one, is a fetching class (I don’t know how to call it..), this class has some static methods interacting with the database (fetchAll, fetchById etc..). The second class is the model itself, it contains all methods for a row of the table (insert, update, delete, validate or any other processing on the row).

Each of the fetching class returns the model object, if it’s a fetchAll, for example, the method will return an array of model, and if its a fetchById the method will return only 1 object, since id is unique.

Example of how I would use it :

$users = Users_Map::fetchAll();

foreach($users as $user)
{
    echo $user->username.'<br/>';
}

$user = new User_Model();
$user->username = 'example';
$user->insert();

$user = User_Map::fetchById(1);
$user->username = 'example2';
$user->update();

If you have any suggestion other than _Map, I’m open.
I’d like to know if this “pattern” is good and what do you think of it, how can I improve it, am I wrong? Should I use only 1 class, having static and non-static method all in the _Model?

Thank you very much for your help/suggestions!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:19:49+00:00Added an answer on May 15, 2026 at 4:19 am

    Sounds reasonable from what you’ve described, though the true test will come when you start seriously extending it.

    I usually build a core of three classes:

    1. a database handler
    2. a generic object handler
    3. a generic collection handler

    Each table gets one derived from the object class to represent one row in the table, and a class derived from the collection which represents some or all of the table and will return individual objects as requested. There is also a static “registration” function for seting up all the necessary information (table name, valid fields, etc) once for each class.

    Sometimes, a collection class is also an object for another table. The generic objects and the registration mechanism I wrote ages ago seamlessly handles this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a game. I want to have game entities each have their own
People have been developing own solutions to the following problems: Consistent messaging frameworks for
I am trying to achieve Model-view separation. My airplane is a class. While developing
I'm developing my first iPhone app, and while implementing user preferences, I have a
When developing my own Java class to use within ColdFusion 8 I stumble upon
I'm developing a time-critical ASMX web service and I'm currently using own class with
I'm thinking about developing my own PHP based gallery for storing lots of pictures,
I am new to UserControls, and while developing my own control I found a
I'm developing a simple Qt 4 app and making my own dialog. I subclassed
Developing websites are time-consuming. To improve productivity, I would code a prototype to show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.