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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:58:40+00:00 2026-06-10T10:58:40+00:00

I am very like to use PDO, so it might be on. Usage could

  • 0

I am very like to use PDO, so it might be on.

Usage could be as:

$m = new MDB();

$m->Users()->GetRec($param);

Users() is a name of table in the database, GetRec($param) is my function.

A way I go looking like this:

class MDB extends DB {

    function __construct(){

        parent::__construct();

        if ($result = $this->pdo->query("SHOW TABLES"))
        {

            while ($row = $result->fetch(PDO::FETCH_NUM))
            {
                // this is only my imagination (not working at all)
                __set($row[0],true);

            }

        }

    }

    // set
    public function __set($name, $value)
    {
        // here could be a method (not properties)
        $this->$name = $value;
    }

Sure it’s all seems not exactly what I want. So I am able to get some suggestions and advices in this question.

upd 1.

Thanks for the magic method __call and now I’m trying to make it within. Watch my updated code:

class MDB extends DB {

    function __construct(){

    parent::__construct();

}

public function __call( $method, $param )
{

    $tables = array();

    if ($result = $this->pdo->query("SHOW TABLES"))
    {

        while ($row = $result->fetch(PDO::FETCH_NUM))
        {

            $tables[] = $row[0];

        }

    }

    if (in_array($method,$tables))
    {

        return $this;

    }
    else
    {

        return FALSE;

    }

}

Well, seems it works for me!

  • 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-10T10:58:41+00:00Added an answer on June 10, 2026 at 10:58 am

    Yes it’s possible! The wrong row in your code is:

    __set($row[0],true);
    

    There you should call:

    $this->$row[0] = true;
    

    Take a look a the simple example below and at the overloading documentation of PHP http://www.php.net/manual/en/language.oop5.overloading.php.

    class A{
    
    //The array which will contain your data
    private $tables;
    
    function __construct($array){
        $counter = 1;
        foreach($array as $value){
            //That's the right call!    
            $this->$value = $counter++;
        }
    }
    
    
    function __set($name, $value){
        $this->tables[$name] = $value;
    }
    
    function __get($name){
        if (array_key_exists($name, $this->tables)) {
               return $this->tables[$name];
        }
    }
    
    }
    
    $array = array('a1', 'a2', 'a3', 'a4', 'a5');
    $a = new A($array);
    
    foreach($array as $key){
        echo $a->$key;
    }
    

    Hope this help!

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

Sidebar

Related Questions

I am very new to Visual Studio but i would like to use it
I am very new to Java. I would like to use some features from
I created a new Spring web app, and I'd very much like to use
I would like to use a very wide image on my website. There is
I would like to use R to generate a very basic world map with
I'd like to use Log4J to send output of a very specific nature to
I know this is very basic. I would like to use jQuery to change
I have a master record which I'd like to use with. Here's a very
For a very simple profiling I use microtime() like this: $now = microtime(); for
For class, I would like a to use PHP MVC framework very similar 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.