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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:58:51+00:00 2026-05-13T06:58:51+00:00

REWROTE: SOLVED Hi there, I currently worked on a simple application with a database,

  • 0

REWROTE: SOLVED

Hi there,

I currently worked on a simple application with a database, a bunch of controllers, views and a model class.

I coded the controllers and inserted the db connections directly

E.g.
Each controller method has his own PDO to connect to a specific database+table.

I refactored this because I had too many active PDOs per 1 controller, so I started to code the model class.

A short information: The model class is once accessed by a controller, when the controller is called.
Once the model object is constructed it is available through the whole controller, and you can pass custom request to it.
E.g. getUserById => Gets the User from the current controller table with the id “xy”.

Now that I finally finished the model class and added my PDO class to the model:
Everytime I want to access any of my controllers, my FireFox asks me where to safe the empty “test.php” (test.php is my index file).

Restarting Apache2 / PHP / MySQL did not work, if I remove a certain part of my code, there is no error, but this part is essential. 😉

model.php

class Model extends db_pdo_adapter{
    public function __construct($name)
    {
        $name = strtolower($name);
        $this->dbh = parent::connect(Model::ATTR_HOST, Model::ATTR_USR, Model::ATTR_PASSWD, Model::ATTR_DB);
        $this->name = $name.'s';
        //$this->ATTR_TBL = $this->name;

    }

    public function __call($name,$values)
    {
        $string = preg_replace('/^get/','',$name);
        $string = strtolower($string);
        $by = preg_split('/by/',$string);
        $by = strtolower($by[1]);
        return $this->get($string, $by, $values); // when I remove this part no empty file is served.
    }

    public function get($item, $by, $conditions) // single item if is_no_array
    {
        if($item = preg_replace('/$s/','',$this->name))
        {
            $item = '*';
        }
        //if(count($conditions) <= 1)
        //{
            $query = 'SELECT ' . $item . ' FROM ' . $this->name . ' WHERE ' . $by . ' = :' . $by . '';
            $pname = ':'.$by;
        //}

        $this->dbh->getStatement($query);
        $this->dbh->bindParam($pname,$conditions[0]); // ->dbh-> also was missing
        $this->dbh->exec();
        return ($this->dbh->fetchAll());

    }
}

Extract of test.php

 header('Content-Type: text/html;');
$time_start = microtime(true);



 include_once('db/model.php');
 //include_once('village.php');
 //include_once('player.php');
 include_once('building.php');

//$village = Village::getVillage('12');
//$player = Player::getPlayer('423');
//$data = array('name' => 'peter','password' => 'nopasswd','email' => 'peter@hasnomail.org');
//$player->newPlayer($data);
//print_r($village->attr);
//print_r($player->playerObj);
//include('interface.phtml');
//var_dump($_SERVER);
//print_r($village);
//print_r($player);
echo '<br />';
var_dump(Building::getBuilding('321'));

Extract of the building.php (controller)

class Building{
    private function __construct($id,$village = NULL)
    {
        $this->model = new Model(__CLASS__);
        $model = $this->model;

        $this->buildingObj = $model->getBuildingById($id);
    }

    public function getBuilding($id,$village = NULL)
    {
        return (new Building($id));
    }
}
  • 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-13T06:58:52+00:00Added an answer on May 13, 2026 at 6:58 am

    I found the problem:

    I have to extend the Model class with the PDO adapter, I do not know why, but this was the problem.

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

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Answer from comments. Glad to have helped. :) Have you… May 14, 2026 at 4:23 pm
  • Editorial Team
    Editorial Team added an answer Can I specify a custom location to "search for views"… May 14, 2026 at 4:23 pm
  • Editorial Team
    Editorial Team added an answer TCP is full-duplex 2-way communication. HTTP uses request/response model. Let's… May 14, 2026 at 4:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.