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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:24:14+00:00 2026-05-31T02:24:14+00:00

OK, this is just a quick question and I might take some slack for

  • 0

OK, this is just a quick question and I might take some slack for this but I’m just looking for a little guidance as I am completely self taught. I do a lot of reading and try to do a lot of building–I’d say I’m coming into a nice intermediate stage of php, mysql, and web knowledge in general–by no means advanced or overly confident–still learning.

I’m really trying to tackle OOP in PHP and so I want to create a good lean database wrapper for MySQL, just MySQL, I’m most comfortable with MySQL and I dont see any reason to use any other database. I dont want to create any sort of portability in the design–I want it to be specific to my database; so I dont want to use PDO.

So the question I have as of right now in the beginning is should I create a class that EXTENDS mysqli and then have create model classes for my database tables that extend that base database class? so class->child = mysqli->DbBase->UsersModel ? This would require a lot of $this statements inside the class, would it not?

Or should I instantiate a mysqli class and pass it to DbBase?

  • 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-31T02:24:15+00:00Added an answer on May 31, 2026 at 2:24 am

    Classes kind of represent things in the real world (or even imaginary “things”), right? An instance of a DB represents a connection to that db. Has a model something in common with a database connection? Not really. I would suggest to include instances of your database class in those models classes you’re going to write, because a model uses a database connection to access it’s data but is not a kind of database connection.

    Concerning Mysqli <-> DBClass: That really depends on what you’re trying to achieve with that DBClass – does it extend Mysqli with some extra functions or anything? If it doesn’t, don’t use inheritance there, otherwise you can use it.


    A very basic example, just to give you the idea: (it is actually a simplified but definitely not complete version of the ActiveRecord pattern)

    abstract class DbTable {
        /* An instance of your DBClass (=Database Connection), to be used if no
         * other connection is specified. */
        protected static $_defaultDbAdapter = null;
    
        /* The db connection to be used by this instance. */
        protected $_dbAdapter = null;
    
        /* The name of the table in the database. */
        protected $_tableName = '';
    
        public static function setDefaultDbAdapter(DbClass $db) {
            self::$_defaultDbAdapter = $db;
        }
    
        public function setDbAdapter(DbClass $db) {
            $this->_dbAdapter = $db;
        }
    
        public function getDbAdapter() {
            if (null === $this->_dbAdapter) {
                $this->setDbAdapter(self::$_defaultDbAdapter);
            }
            return $this->_dbAdapter;
        }
    
        public function insert(array $data) { /*...*/ }
        public function update(array $data, $where) { /*...*/ }
        public function delete($where) { /*...*/ }
        public function select($where) { /* may e.g. return an array of DbTableRow childclass instances */ } 
    
        // ...
    }
    
    class Users extend DbTable {
        protected $_tableName = 'my_users_table';
    }
    
    abstract class DbTableRow {
        /* The row itself (may be not yet saved to the db!) */
        protected $_data = array();
    
        /* The row as it is in the database (to find differences, when calling save()). */
        protected $_cleanData = array();
    
        /* An instance of the table that this row belongs to. */
        protected $_table = null;
    
        public function __construct(DbTable $table, array $data = array()) { /*...*/ }
        public function save() { /* uses $this->_table->insert()/update() */ }
        public function __get($key) { /*...*/ }
        public function __set($key, $value) { /*...*/ }
        // ...
    }
    
    class User extends DbTableRow { }
    

    Usage:

    // Make a new connection to the database
    $db = new DbClass('...'); // or whatever you name that class...
    
    // Set this connection to be the default connection
    DbTable::setDefaultDbAdapter($db);
    
    // Create a new user
    $users = new Users();
    $user = new User($users);
    $user->email = 'test@example.com';
    $user->save();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy (therefore quick) way to accomplish this? Basically just take some
This is just a quick question to understand correctly what happens when you create
This is just a quick question in C#. I have a scenario where I
Just a quick question about how you would go about implementing this. I want
I was just writing some quick code and noticed this complier error Using the
I am using EF4. Just a quick question, is this a really good framework?
Just a quick question. I suppose I could just try it but I like
Quick question, looking for some recommendations. I have a site that will be requesting
This should a quick question for some easy rep. I'm doing some PHP Website
Hey just a quick question for anyone who has done this. I want to

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.