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

Ask A Question

Stats

  • Questions 444k
  • Answers 444k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer STRUCT is an oracle class that implements the java.sql.Struct interface.… May 15, 2026 at 6:25 pm
  • Editorial Team
    Editorial Team added an answer They aren't more customizable than HMENUs, they're just easier to… May 15, 2026 at 6:25 pm
  • Editorial Team
    Editorial Team added an answer Had to write a function to parse the URL. Seen… May 15, 2026 at 6:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.