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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:06:26+00:00 2026-05-20T16:06:26+00:00

I am using the Active Record design pattern in my web app, and after

  • 0

I am using the Active Record design pattern in my web app, and after looking at the code in my class that handles CRUD (create, read, update and delete) on a table in the DB, i’m wondering if there’s a better way to set the data.

Let’s say my table has around 15 columns, and my class has 15 member variables to represent the columns. I have a form which allows a user to input data for each of those variables, and on submit, my script reads everything from _POST and _GET and compiles it into an array called $params.

Currently my class setter methods looks like this:

public function setData($data1, $data2, $data3,...,$dataN-1){
   $this->data1 = $data1;
   $this->data2 = $data2;
   $this->data3 = $data3;
   ...
   $this->dataN-1 = $dataN-1;
}

I was wondering, what the problems would be if I changed the setData argument to be an array, specifically the array containing the _POST and _GET values, so something like this

public function setData($data){
   $this->data1 = $data['data1'];
   $this->data2 = $data['data2'];
   $this->data3 = $data['data3'];
   ...
   $this->dataN-1 = $data['dataN-1'];
}

Assume that all the form element names are correct. Obviously, the time will be saved when I call the method, not having to list 15 arguments. I am going to be using prepared statements for all INSERTs and UPDATEs. Are there any other pitfalls that I should be aware of doing this?

Thanks a lot for your help.

  • 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-20T16:06:27+00:00Added an answer on May 20, 2026 at 4:06 pm

    Why don’t you use an array too for $this->data[] in your class?

    You could this way use a foreach and could maintain/automatize it more easily, fetching data or setting it in your DB.

    EDIT : this way you fill your array

    in your class :

    private $data = array(
       'db_column_name_1' => null,
       'db_column_name_2' => null,
       'db_column_name_3' => null,
       ...
       'db_column_name_n' => null
    );
    
    public function setData($data){
       foreach ( $this->data as $key => $value )
         $this->data[$key] =  $data[$key] ;
    }
    

    Symmetrically you could as easily make the right INSERT/UPDATE query

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

Sidebar

Related Questions

As I know ruby on rails are using Active Record with table per class
I am working on a project using Castle Active Record. I stumbled across the
I'm looking at moving my application from using active directory membership provider to using
Using class table inheritance it is recommended that the subclass refers to the superclass
I'm using Codeigniters Active record library to carry out an update on a column
We are running a website using Active Server Pages & COM+ components . The
I am creating a store using Active Merchant and PayPal sandbox right now. It
I am investigating the use of web frameworks with my Java web-app. My basic
I'm developing software using the Google App Engine. I have some considerations about the
I have recently been using cookie store and I want to transition to active

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.