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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:53:11+00:00 2026-05-25T23:53:11+00:00

I have the following PDO Initialization set in my constructor for a PDO wrapper:

  • 0

I have the following PDO Initialization set in my constructor for a PDO wrapper:

public function __construct($engine, $host, $username, $password, $dbName)
{
    $this->host = $host;
    $this->dsn = $engine.':dbname='.$dbName.';host='.$host;
    $this->dbh = parent::__construct($this->dsn, $username, $password);
    $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);      
}

My main problem is that when I set dbh to initialize as a parent in a constructor, it returns NULL.

and that creates a chain reaction.

Is there anything specific that I’m doing wrong?

  • 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-25T23:53:12+00:00Added an answer on May 25, 2026 at 11:53 pm

    You are mixing up wrapping a class and inheriting a class.

    Either do this (wrapping):

    class YourDB
    {
        public function __construct($engine, $host, $username, $password, $dbName)
        {
            $this->host = $host;
            $this->dsn = $engine.':dbname='.$dbName.';host='.$host;
            // here we are wrapping a PDO instance;
            $this->dbh = new PDO($this->dsn, $username, $password);
            $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);      
        }
    
        // possibly create proxy methods to the wrapped PDO object methods
    
    }
    

    Or (inheriting):

    class YourDB
        extends PDO // extending PDO, and thus inheriting from it
    {
        public function __construct($engine, $host, $username, $password, $dbName)
        {
            $this->host = $host;
            $this->dsn = $engine.':dbname='.$dbName.';host='.$host;
            // here we are calling the constructor of our inherited class
            parent::_construct($this->dsn, $username, $password);
            $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);      
        }
    
        // possibly override inherited PDO methods
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $link = new PDO(mysql:dbname=$databasename;host=127.0.0.1,$username,$password); $query = $link->prepare(SELECT * FROM
I have following wrapper to help me manage the wcf client lifetime: public class
I have following Linq query/function in my MVC3 application. public AuditTrail GetNamesAddressesEmployers(long registryId ,
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following classes. class A { public: void fun(); } class B: public
I have the following function which enables a query to run with a where
I have the following insert function. Is it safe from a sql injection. If
I have the following set-up: Zend Framework 1.10.8 database adapter: pdo_mysql memory limit: 128MB
I have the following function <?php error_reporting(E_ALL); ini_set("display_errors", true); @ $dbh= new mysqli('localhost', 'root',
I've got the following saved into my dbConnect.php file $host = 'localhost'; $username =

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.