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

  • Home
  • SEARCH
  • 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 5982627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:06:50+00:00 2026-05-22T22:06:50+00:00

I have been looking for help online on how to design my php classes

  • 0

I have been looking for help online on how to design my php classes to separate my business logic and my data layers. I had started to design a class I thought was pretty cool but then discovered PDO and ADODB and had a nice facepalm moment realizing I was recreating the wheel. My problem now is I still don’t quite understand how to separate my logic and all my SQL queries.

I stripped out mostly everything from my DB schema and put down these two tables because I think they’d be pretty easy to understand. Let’s say I have Files with the path where they are saved on my server which are in Directories (these Directories can be in other Directories). Let’s say I’ll need basic features like fetching the root Directory from one of my files or get a list of Directories inside the current Directory.

+--------------------+ +----------------+
| Files              | | Directories    |
+--------------------+ +----------------+
| id                 | | id             |
| name               | | name           |
| path               | | directory_id   |
| directory_id       | +----------------+
+--------------------+

Would a well designed class look like this:

class Files {
    public function __construct( $file_id ) {}
    public function getDirectory() {}
    public function getRootDirectory() {}
    public function getPath() {}
    public function move( $directory_id ) {}
}

class Directories {
    public function __construct( $directory_id ) {}
    public function getRootDirectory() {}
    public function move( $directory_id ) {}
    public function listContent() {}
}

Where I’d fetch all the data for my objects in the constructor using the ID passed through the constructor? Should I pass a PDO object in the constructor as well or am I missing some valuable design pattern? Should all the SQL be hardcoded in here? One thing I get with PDO is that I could switch from MySQL to MSSQL very easily but both have differences in the syntax of their SQL so wouldn’t still cause me problems?

I know these are more theoretical questions without ONE good answer but I lack work colleagues to discuss this with (I’m not kidding when I say they don’t even know what a design pattern is) so I find myself turning to the web. If my question is too vague feel free to suggest a good discussion type place I could ask this kind of stuff and I’d be extremely grateful 🙂

  • 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-22T22:06:51+00:00Added an answer on May 22, 2026 at 10:06 pm

    It’s hard to tell just how much this would apply to your real-world situation, but you should probably look up what an ORM (Object-Relational Mapping) can do for you. There are many, many very useful ORM solutions out there, that can make this stuff much simpler. They’re not all right for every solution, of course, but ORMs can help you implement your logic in the middle tier, where it belongs (usually).

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

Sidebar

Related Questions

I have been looking for a tutorial to help me integrate PHPUnit with CakePHP.
I have been looking at nestedSet behaviour in symfony using doctrine, to display a
i have been doing some looking at dlls. what exactly are all the uses
Been looking around the web, but not found anything so far... can anyone help?
I have an app leveraging Core Data SQLITE3 that works perfectly in the simulator.
I want to add gradient to my page. I have used java code throughout
In page_load, I create a table and fill it with data gathered from a
I'm trying to figure out how to POST JSON from Android by using HTTPClient.
Ok so I am very new to the Android SDK, but not to programming.

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.