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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:45:29+00:00 2026-05-23T16:45:29+00:00

I have a question regarding performance when using OOP in PHP together with databases.

  • 0

I have a question regarding performance when using OOP in PHP together with databases. I’ll ask my question by example, suppose a class foo represents a row from some table. Now suppose I need to use foo at 5 different pages on my web app.

The catch is that on each of the 5 pages I will use data from different columns. (i.e. the first page will use column1 and column2 while the second page uses column3 and column 4, etc..)

The OOP approach (as far as I can see) would suggest that when I initialize foo on some particular row I would connect and fetch all the columns of that row and build my object. I could then proceed with my logic and use whatever data that I might need.

The issue I have with this is that with the procedural approach (which I’m more used to when it comes to web) would not waste resources to download columns that I do not need since the query would be specifically tailored to the needs of the particular page.(i.e. If im on the first page I would only download column1 and column2 since that’s what I need.)

Am i going about the OOP approach wrong or is the extra overhead so insignificant that developers in general download data which they do not need?

Thanks and sorry if this has already been covered, I thought it would be an interesting topic! 🙂

Erik

further clarification:

The class is like:

class foo
{
  $column1;
  $column2;
  $column3;
  $column4;

  public function _construct($id)
  {
    //get column 1,2,3 and 4 from database where table_id = $id
  }
}

The issue is that if i only need column1 one one page i download column2,3 and 4 for nothing. In procedural approach you would not do that. Is my OOP model bad or is this ok?

  • 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-23T16:45:29+00:00Added an answer on May 23, 2026 at 4:45 pm

    You can still incorporate the selective query inside of an OOP class by using either an array of columns to grab upon construction, or by using a public class method to handle the query grabbing.

    Example of constructor:

    <?php
    
    class Foo{
        public function __construct( $column ) {
    
            if(is_array($column)){
                 if(count($column) > 1){
                     $result = mysql_query('SELECT `'.implode('`,`', $column).'` FROM `table`;');
                 }else{
                     $result = mysql_query('SELECT `'.$column[0].'` FROM `table`;');
                 }
            }else{
                 $result = mysql_query('SELECT `'.$column.'` FROM `table`;');
            }
    
            $this->result = mysql_result($result, 0);
        }
    }
    ?>
    

    The public function method would be identical to that, except you could return the result instead of setting $this->result.

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

Sidebar

Related Questions

I have a question regarding performance of SQL Server. Suppose I have a table
I have some question regarding database performance in general. I'm using Sqlite but I
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have a question regarding dependency injection. say i want to create a class
I have a question regarding static function in php. let's assume that I have
I have a question regarding the integration of business objects developed using Linq To
I have a question regarding the development of liferay portlets using the liferay plugin
I have a web design issue regarding to performance to ask advice. On a
I have question regarding the use of function parameters. In the past I have
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record

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.