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 6105397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:58:10+00:00 2026-05-23T13:58:10+00:00

Okay so I’ve got the hang of the basics writing classes and methods, and

  • 0

Okay so I’ve got the hang of the basics writing classes and methods, and extending them.

I could easily write a massive class with all the methods I could possibly want or several classes that just keep extending each other in a chain. But things are starting to get difficult to manage.

I am wondering if I could do something like the following code so I can keep “modules” separated, and only fire them up when required.. I hope this makes some sort of sense as to what i’m hoping to achieve:

// user/member handling methods "module"
class db_user
{
    public function some_method()
    {
        // code that requires parent(?) objects get_something() method
    }
}

// post handling methods "module"
class db_post
{
    public function some_method()
    {
        // code that requires parent(?) objects update_something() method
    }
}

class db_connect()
{
    public $db_user;
    public $db_post;

    public function __construct()
    {
        // database connection stuff
    }
    public function __destruct()
    {
        // blow up
    }

    // if i want to work with user/member stuff
    public function set_db_user()
    {
        $this->db_user = new db_user();
    }

    // if i want to work with posts
    public function set_db_post()
    {
        $this->db_post = new db_post();
    }

    // generic db access methods here, queries/updates etc.
    public function get_something()
    {
        // code to fetch something
    }

    public function update_something()
    {
        // code to fetch something
    }
}

So i would then create a new connection object:

$connection = new db_connect();

Need to work with users so..

$connection->set_db_user();
$connection->db_user->some_method();

And now i need to do something with posts so..

$connection->set_db_post();
$connection->db_post->some_method();
$connection->db_post->some_other_method();

I hope someone can help me out here, I’ve been searching for a few days but can’t seem to find any info other than to basically keep it all in one class or create an endless chain of extensions – which isn’t helpful because while I want everything to work through one “interface” I still want to keep the “modules” separate.

My apologies if this seems utterly ridiculous somehow – I am a novice after all..

  • 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-23T13:58:11+00:00Added an answer on May 23, 2026 at 1:58 pm

    Pass db_connection into the db_* classes:

    class db_user
    {
        protected $db;
    
        public function __construct($db)
        {
            $this->db = $db;
        }
    
        public function some_method()
        {
            // code that requires parent(?) objects update_something() method
            $this->db->update_something();
        }
    }
    

    Use:

    $db = new db_connection();
    $user = new db_user($db);
    $user->some_method()
    

    The db_connect should not have set_db_user, set_db_post, etc. It should handle connecting to the db and maybe some generic select/update/insert/delete methods

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

Sidebar

Related Questions

Okay, so I've got FavoritesList extending GalleryList which extends ListFragment: public static class FavoritesList
Okay, I have GOT to be missing something totally rudimentary here. I have an
Okay, I have a WinForms C# program I am writing in Visual Studio 2010
Okay first the code.. <td class=btnSaveBooking> <div class=btnSaveBookingContainder> <div id=save> <span class=btnImage></span><span class=btnsavebookingspan> <input
Okay, so I'm running a small test webserver on my private network. I've got
Okay so I have a list of addresses and next them there is a
Okay I got some good advice for Mobile Detection but still having an issue
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess

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.