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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:51:39+00:00 2026-06-11T12:51:39+00:00

Right now, I am developing two classes for interaction with a MySQL database –

  • 0

Right now, I am developing two classes for interaction with a MySQL database – one extends the other. Here they are:

class DB_MySQL {

    protected $dbuser;
    protected $dbpass;
    protected $dbhost;
    protected $dbname;
    protected $dbh; // Database connection handle

    public function __construct($dbuser, $dbpass, $dbhost, $dbname)
    {
        $this->dbuser = $dbuser;
        $this->dbpass = $$dbpass;
        $this->dbhost = $dbhost;
        $this->dbname = $dbname;
    }

    //Used to create connections - almost always called by execute()
    protected function connect()
    {
        try
        {
            $this->dbh = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
        }
        catch(PDOException $e)
        {
            print "Error!: ".$e->getMessage()."<br/>";
            die();
        }
    }

And the child class:

class CheckOut extends DB_MySQL{

     function __construct() 
    {
        parent::__construct();
    }
}

I just started writing them, so there is no “meat” to them yet. If anyone sees any major issues or any suggestions, don’t hesitate to point it out.

My question, though, is how the child constructor will interact with the parent’s. My plan is to simply create a CheckOut object without initiating the parent’s. As it can be seen, my parent constructor takes four values. So, do I have to redefine those values in the child constructor? To be clear, I mean:

class CheckOut extends DB_MySQL{

     function __construct($dbuser, $dbpass, $dbhost, $dbname) 
    {
        parent::__construct($dbuser, $dbpass, $dbhost, $dbname);
    }
}

and of course define those variables. Or can I add those values when I create the object and it will implicitly be passed?

Any help is appreciated.

  • 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-11T12:51:40+00:00Added an answer on June 11, 2026 at 12:51 pm

    If the constructor of the child class doesn’t do any other things, then you could omit the constructor.

    Just the below is ok:

    class CheckOut extends DB_MySQL{
    }
    

    But if the child class’s constructor need do some other work, yes, you need to do:

    class CheckOut extends DB_MySQL{
    
        public function __construct($dbuser, $dbpass, $dbhost, $dbname) 
        {
            parent::__construct($dbuser, $dbpass, $dbhost, $dbname);
            do_some_other_work();
        }
    }
    

    When you use, you both need to call:

    $checkout = new CheckOut($dbuser, $dbpass, $dbhost, $dbname);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I am developing my first website. Right now, I am implementing PHP's MySQL
I am developing an app right now that reads in data from a windows
Right now, I'm extremely frustrated because I was in the process of developing some
I'm developing a facebook app right now all by my lonesome. I'm attempting to
I'm developing in rails right now and I was wondering if there are any
So I'm developing and iPhone game right now and everything has been working just
I'm developing a Grails App. I have about 20 Controllers right now and there
I'm developing a new gem (fork of nifty-generators). Right now my deployment consists on
i am developing an android todo list app to learn. right now in my
I am running into some problems right now. I am developing a card game

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.