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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:52:48+00:00 2026-06-16T02:52:48+00:00

I am creating a database connection class as an abstract in the super-class. Am

  • 0

I am creating a database connection class as an abstract in the super-class. Am using PDO in php. I want to make it abstract so that i can declare specific database connection sub-classes for mysql, oracle, postgre, etc.

I have a connection method in the abstract super-class that i have also declared as abstract. My problem now is, can i make this connection method also static in the sub-class? I want to know if it is the right thing to do.

EDIT

//SUPER CLASS
abstract protected function connectToDatabase($hostname, $dbName, $userName, $password="");


// SUB CLASS
public static function connectToDatabase($hostname, $dbName, $userName, $password=""){

        $this->setHostName($hostname);
        $this->setDbName($dbName);
        $this->setUserName($userName);
        $this->setPassword($password);
        $this->setDatabaseType(DATABASE_TYPE);
        $dsn = $this->getDatabaseType(DATABASE_TYPE) . ":" . parent::getHostConst() . "=" 
              . $this->getHostName() . ";" . parent::getDbNameConst() . "=" . $this->getDbName();
        $pdo = new PDO($dsn, $username, $passwd);
        $this->setPdoConnection($pdo);
}
  • 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-16T02:52:49+00:00Added an answer on June 16, 2026 at 2:52 am

    From looking at your code i would say you can’t make them static as you are then refering to $this in them. What should $this mean in a static method?
    A static method only exists once in the class and not does not refer to a special object.

    For example take a look at: When to use self over $this?

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

Sidebar

Related Questions

I'm creating a database application using ASP.NET and I want to make a Windows
I'm currently creating a lot of classes that will access database using a connection
I'm creating a class that will manage a connection to a Firebird database. The
Just to ensure that I am correctly creating and closing database connection, I wrote
I want to create a global connection class from Sql server database to vb.net
I got a common jar that used for creating Database Connection Pool with the
I'm creating a new PHP application and want to make sure I get the
I am using libpqxx to connect to a postgres database by creating a class.
Situation: I have a static Database class, using HSQLDB and I want to use
I am programmatically creating a database connection object inside a simple procedure (not a

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.