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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:38:43+00:00 2026-05-12T10:38:43+00:00

I have a CORE class that pertains only to my specific site, ie, it

  • 0

I have a CORE class that pertains only to my specific site, ie, it performs site specific functions. I have a database class (for mysql), and other classes like access, validator, upload, template etc etc… I know that php classes can only extend one class each, so almost all of my classes extend the database class. I was looking over a public twitter class used on the twitter API. In it, there are functions to do almost everything you could do by going directly to the website, insert, delete, whatever… Should I put all site relatie functions inside my Core class and keep it out of the general scope of my scripts. Right now I have something like this….

Heres an example, as of right now I have functions like

$core = new Core();
$core->get_user_info($user_id);
$core->get_user_articles($user_id);

Inside that function, i perform database queries to select the needed information so i dont have to do it directly since it can get messy.

I also have functions to delete things, like

$core->Delete_Article($article_id);

However, I dont have functions to insert. Instead I use the Database class directly to add information, like so.

$article = array(user_id => $_SESSION['user_id'], body => $_POST['body']);
$db = new Database();
$db->Insert($article, 'articles');

or

$user = array(name => $_POST['name'], email => $_POST['email']);
$db->Insert($user, 'users');

Now, in the topic of separation of one aspect from another, should I put ALL of my database select/insert/update/delete queries inside my general CORE class and do ALL the database actions in the background

Like instead of $db->Insert(), i could use $core->insert_user() or just continue as I’m doing.

  • 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-12T10:38:44+00:00Added an answer on May 12, 2026 at 10:38 am

    This is a pretty common mistake for people new to object-oriented programming. You don’t want to extend a class just because it has some functions that you need. In fact, you may want to avoid extending classes at all while you’re getting started. Although most intros to OOP make a big deal out of inheritance, I would steer clear for the moment.

    Instead, think of how you can group together functions in terms of the way they’re used. For example, say you’re managing users. You need to keep track of user information, add users, delete them, etc. You could create classes like this:

    class User {
      function getName()...
      function getID()...
    }
    class UserAdmin {
      function addUser(User $user)...
      function getUser($id)...
      function deleteUser($id)...
    }
    

    These classes are organized according to concepts, not according to what functions you need to call.

    When you do need reusable functions for things like database access, you’ll generally want another separate object doing the work. So instead of having your UserAdmin class extend a Database class to format its SQL:

    // wrong
    class UserAdmin extends Database {
      function getUser($id) {
        $this->openConnection();
        $this->runQuery("select * from users where id = {1}", $id);
      }
    }
    

    … you can just use the Database class from within your UserAdmin class:

    // right
    class UserAdmin {
      function getUser($id) {
        $db = new Database();
        $db->openConnection();
        $db->runQuery("select * from users where id = {1}", $id);
      }
    }
    class Database {
      function openConnection() ...
      function runQuery() ...
    }
    

    Initially it will seem like more work, but it keeps your various classes independent. That makes them easier to write, maintain, and test.

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

Sidebar

Related Questions

I have a handful of DBIx::Class::Core objects that model various database tables. For some
I have a simple core class that is being used for core functions to
I have a Java class that accesses a MySQL database through JDBC that I
Hi i have these classes: class Core < ActiveRecord::Base belongs_to :resource, :polymorphic => true
I have a program like this - import weka.core.stemmers.SnowballStemmer; public class TestProject{ public static
Sup! We have core class with mysql connection, than we include plugin and we
I have an Event database loaded into Core Data that has duplicate Event titles.
I have a class that is a core component of a performance sensitive code
I have a class that takes an NSString as a parameter, uses Core Text
I have a class that retrieves data from core data and stores it into

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.