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

  • SEARCH
  • Home
  • 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 8099089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:17:20+00:00 2026-06-05T22:17:20+00:00

I am currently trying to build myself a nice few classes to build my

  • 0

I am currently trying to build myself a nice few classes to build my pages a bit faster.

I currently have this setup,

// page class
class Page extends DBC {
    // creates a page
    public function create($data = false) {
       echo 'SOME BASIC HTML TO SETUP PAGE';
       // pass the database connection var to content function
       content($this -> $dbc, $data);
       echo 'SOME BASIC HTML TO SETUP PAGE';
    }
}
// dbc class
class DBC {
    public $dbc;
    public function __construct() {
        // sets the database connection
    }
}

And for each new page I create I just do this after requiring my classes into the script.

// content function
function content($dbc) {
    // some content
    // am able to use dbc
}
// new page object
$page = new Page();
// am able to use dbc var fine here too
$page -> dbc -> // execute a query
// create page
$page -> create();

But the problem I face now is how best to create functions inside my DBC class to make my query building faster. I tried adding the following function to the class DBC,

public static function query($q, $data, $options = array()) {
    // execute prepared query
    $q = $this -> dbc -> prepare($q);
    return $q -> execute($data);
}

But I cannot use this inside my content function as only the database connection is passed into it and the query function inside the DBC class uses the connection in object context.

My question after explaining my problem is as follows;

Would it be best to make the functions that execute querys for me inside my DBC class static and just pass in the existing connection?

OR

Would it be better to pass the whole DBC object to my content function inside the Page class like below,

content(new DBC(), $data);

That way allowing me to use the functions in object context. The Page class still needs to be extended by the DBC class as I need to use the dbc var outside of the content function too. But wouldn’t this then make 2 instances of the DBC class one when it is extended by Page and one when passed into the content function?

Thanks for taking the time to read this question and for any answers given!

  • 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-06-05T22:17:22+00:00Added an answer on June 5, 2026 at 10:17 pm

    Going by what i understand, i think an example would be best so you can take a look and make improvements as per your requirements.
    Check this class i wrote on github
    And check out this gist on usage
    So all I’m saying is, look at it and come up with a solutions that suits your needs or you could just use it… it’s free of course

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

Sidebar

Related Questions

I am currently trying to build a program where I have a recursive function
I'm trying to build firefox but I'm having some problems. I currently have Visual
I'm currently trying to build a class hierarchy automatically by using C++ templates. The
I am currently trying to build a Java Project with several dependencies. I have
i am currently trying to build a html5 video page with restrictive access to
I have gotten myself a little confused with this. I am trying to make
I am currently trying to build an iterator for a custom class and it's
Hi I'm trying to build a little gallery for myself and tried this link
I am currently trying to build on TeamCity, which uses Microsoft.Office.Interop dll. This will
I'm currently trying to build a provisioning service of a kind for a local

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.