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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:21:18+00:00 2026-06-02T19:21:18+00:00

I have designed following class <?php class DB { private static $objInstance; /* *

  • 0

I have designed following class

<?php 

    class DB { 

        private static $objInstance; 

        /* 
         * Class Constructor - Create a new database connection if one doesn't exist 
         * Set to private so no-one can create a new instance via ' = new DB();' 
         */ 
        private function __construct() {} 

        /* 
         * Like the constructor, we make __clone private so nobody can clone the instance 
         */ 
        private function __clone() {} 

        /* 
         * Returns DB instance or create initial connection 
         * @param 
         * @return $objInstance; 
         */ 
        public static function getInstance(  ) { 

            if(!self::$objInstance){ 

                $ini_array = parse_ini_file("db.ini");

                $dbInfo['server'] = $ini_array['server'];
                $dbInfo['database'] = $ini_array['database'];
                $dbInfo['username'] = $ini_array['username'];
                $dbInfo['password'] = $ini_array['password'];

                $dsn = 'mysql:host='.$dbInfo['server'].';dbname='.$dbInfo['database'].'';

                self::$objInstance = new PDO(DB_DSN, $dbInfo['username'], $dbInfo['password']); 
                self::$objInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
            } 

            return self::$objInstance; 

        } # end method 

        /* 
         * Passes on any static calls to this class onto the singleton PDO instance 
         * @param $chrMethod, $arrArguments 
         * @return $mix 
         */ 
        final public static function __callStatic( $chrMethod, $arrArguments ) { 

            $objInstance = self::getInstance(); 

            return call_user_func_array(array($objInstance, $chrMethod), $arrArguments); 

        } # end method 

    }
?>

My problem is when I want to perform a query I get following error:

Fatal error: Call to undefined method DB::query()

foreach(DB::query("SELECT * FROM content_type_video") as $row){ 
    print_r($row); 
}

Any ideas why and how to fix this?

  • 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-02T19:21:19+00:00Added an answer on June 2, 2026 at 7:21 pm
    $db = DB::getInstance();
    
    foreach($db->query("SELECT * FROM content_type_video") as $row){ 
        print_r($row); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed the following class that should work kind of like a method
I have a class whose new method has been made private because I want
I have the following class designed to provide a type-safe mechanism to pass an
I have the following situation I have one swt class which displays a simple
I have the following code which is designed to create an onchange event handler
I have Designed the Javascript function My.js it contains following code My.js function display(){
I have the following problem: I have a generic EF repository using DbContext designed
I have the following regexp: (?P<question>.+(?<!\[\[)) It is designed to match hello world! in
I have designed database tables (normalised, on an MS SQL server) and created a
One of the advice given by Joshua Bloch is that, class should be designed

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.