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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:45:03+00:00 2026-06-08T07:45:03+00:00

I am using PDO to make the connection to the DB. I was wondering

  • 0

I am using PDO to make the connection to the DB.
I was wondering how should i structure it using the MVC pattern.

Currently i have it like this:

/model/DatabaseConfig.php

/model/DB.php

/model/Model.php

/model/MySQLDB.php

/model/User.php

View/index.php

What do you think about it?
Is it ok? Should i place DB, Model and MySQLDB in another subfolder?

Thanks.

  • 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-08T07:45:04+00:00Added an answer on June 8, 2026 at 7:45 am

    You should have a look at DAO design pattern http://en.wikipedia.org/wiki/Data_access_object. It allows for the separation of Models and Database interface, which will be very useful if at some point you want to switch the database.

    You might also want to read more about it in this article http://www.sitecrafting.com/blog/php-patterns-part-ii/

    It’s a matter of preference, but I would structure them in the following manner

    Model/User.php 
    DAO/MySQLDB/User.php 
    DAO/MySQLDB.php (old DB.php)
    Config/DatabaseConfig.php 
    View/Index.php 
    MySQLDB.php
    

    Model would contain all the Model classes with Business Logic in them
    DAO would contain all the generic database SQL scripts and connections
    Config would contain all the configuration scripts
    View all the views
    Not sure what the DB.php does, so not sure where to place it.

    Steve was asking in the comment about the difference between Model/User.php and DAO/MySQLDB/User.php, hope this example will illustrate it well

    class Model_User
    {
        public function hashPassword($password)
        {
            $salt = SALT_STRING;
            return hash("sha512", $password.$salt);
        }
    
        public function getById($id)
        {
        $id      = (int) $id;
        $db_data = new MySQLDB_User();
        $db_data->getById($id);
        return $this;
        }
    }
    

    and

    class MySQLDB_User
    {
        public function getById($id)
        {
            $sql = "SELECT * FROM `users` "
            ." WHERE `id` = \"" . $this->_db_connection>real_escape_string($id)
            . "\" LIMIT 1";
            $result = $this->query($sql);
            $this->_parseRow($result);
            return $this;
        }
    }
    

    Have a look at how the biggest frameworks structure their folders i.e. Zend Framework example is here http://framework.zend.com/manual/en/project-structure.project.html

    They usually thought long about the set up, and most of the developers are familiar with it, so if you have a new hire, they will be able to find their way around the custom built system quicker than they would otherwise.

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

Sidebar

Related Questions

I am using php PDO and I have this error when I use the
I have some pages that make PDO queries using prepare() and execute() (binding some
I have started using PDO in php for the first time. Here is my
Can someone confirm this: If I am using PDO::PARAM, I don't need to Filter
Lets say I have a class like this: Class User { var $id var
I'm using PDO and trying to make my application support both MySQL and SQLite,
Simple question and i want simple answer. I'm using PDO prepared statements to make
I am using the PDO Database Abstraction library to make sure my code is
How do I use PDO FetchObject results with the $this variable? Have a page
I just started using PDO (loving it!). Still trying to learn the basics. Currently

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.