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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:50:26+00:00 2026-05-30T13:50:26+00:00

I’m trying to learn oop. I’m working with PHP-MySQL. And I have troubles about

  • 0

I’m trying to learn oop. I’m working with PHP-MySQL. And I have troubles about database jobs with oop way (save, update, get etc.).

Let me explain it with an example project.

Lets say I want to make a site with multiple user types. I have a single database table with an enum “type” field. And I made classes like these:

abstract class User {
 //common properties, functions etc.. like id, username.
}

class Admin extends User {
 protected $type = "ADMIN";
 //I want here to have admin specific fields, functions etc...
}

…and some other user types like that. Here is the thing. I want a common class that can save and update objects into database. What’s the way to do that? I’ll make an object like $user = new User(); bla.. bla.. and I’ll say “Save this user” but how? Do I have to make functions for each of my classes that have specific SQL statements like “INSERT INTO table(name, pass, etc) VALUES (‘name’, ‘pass’, etc)”?

Another point is I want a common factory class that returns me an object. An example I’ll say “Get me the user which have this id and instantiate it with admin class if that user is an admin or the other classes like that”.

And I need some help about “how to instantiate like mysqli_fetch_assoc() result with objects”. That returns an array. Do I need to do like “$object->setId(returned_array[“id”])”?

I’ve looked some books like PHP in Action, PHP Objects, Patterns and Practice but couldn’t find this database specific topics. I hope I could explained it well and sorry for my bad English 🙂

  • 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-30T13:50:28+00:00Added an answer on May 30, 2026 at 1:50 pm

    I think you need an ORM framework. It’s hard to create a good one on your own but you can find a few existing frameworks. Be carefulf do not use a framework with active record pattern becouse it’s an antipattern.

    To fetch objects: http://www.php.net/manual/en/mysqli-result.fetch-object.php

    But I also recommend you to use mysqli in OO way:

    $resource = new mysqli(/* ... */);
    $resource->fetch_object(/* ... */)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.