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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:22:32+00:00 2026-05-25T15:22:32+00:00

if someone could help me with a conceptual question it would be great: Suppose

  • 0

if someone could help me with a conceptual question it would be great: Suppose I have a model that deals with a table called Persons. Normally I would have a standard fetch function like this:

public function fetchPersonById($person_id)
{
$result = 0;

if ((int)$person_id > 0) {
    $select = $this->select()
                    ->from($this->_name, array('Id' => 'Person_Id',
                                            'Name' => 'Person_Name',
                                            'Age'  => 'Person_Age',
                                    'Sex'  => 'Person_Sex'));

                    ->where('Person_Id = ?', $person_id);

    $result = $this->fetchRow($select);
}
return $result;
}

Now suppose for some reason I need to fetch a person’s Sex by it’s Name.. and later on it’s age by it’s name. Would you them add different functions like:

public function fetchPersonSexByName($person_name)
{
// ...
    ->from($this->_name, array('Sex'  => 'Person_Sex');
    ->where('Person_Name = ?', $person_name); ...
// ...
}

and so on… After a while you could see yourself with thousands of short methods like this.. Are you guys that specific or you wether pull the whole record (fetchall) and than later in the code just keep the column you want to use? On this case wouldn’t you be breaking the whole MVC because if I want to get
someone’s Sex my model (or whoeve is calling the function) would need to know the columns name in the database?

I also tought about doing something more generic like

public function $this->fetchColumnA_By_ColumnB_ColumnBValue($columnA_name,  
$columnB_name, $columnA_name)
{
    //...
}

And than have my short methods to be calling this more flexible column. So that I would have something like:

public function fetchPersonSexByName($person_name)
{
    //...
    $this->fetchColumnA_By_ColumnB_ColumnBValue('sex', 'name', 'martin');
}

Anyway.. How do you guys approach this probably common issue?

  • 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-25T15:22:33+00:00Added an answer on May 25, 2026 at 3:22 pm

    I would tend to do a version of your last generic example. The generic method would be protected (or even private) and your more specific (public) methods would call this. To avoid code repetition.

    However, I’m not sure how generic I would go. May be just…

    protected function _fetchColumnById($id, $column) {...}
    
    protected function _fetchColumnByName($name, $column) {...}
    

    …but this would depend on the requirements.

    you could see yourself with thousands of short methods

    If you think you’ll get to 1000’s of requests, then it might be better to read the whole record(s) and cache this somehow?

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

Sidebar

Related Questions

hope someone could help me to understand how to solve my question. I have
I really REALLY hope that someone could help me. I have to pass almost
I was wondering if someone could help me with a simple question? i have
I was wondering if someone could help me. Suppose I have some classes as
If someone could help me point in the right direction that would be awesome
I have 2 blocks of code, if someone could help me put them together
could someone help me with the regex pattern that i could use to match
Could someone help me on this, I have created simple web services using axis2
I was wondering if someone could help with this: I have a series of
HI All I was hoping someone could help me improve a query I have

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.