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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:35:06+00:00 2026-06-07T06:35:06+00:00

I am creating a class (Datamap) that will help me simplify my queries in

  • 0

I am creating a class (Datamap) that will help me simplify my queries in my model class. Basically, this class (Datamap) is use in conjunction with my db class.

Previously for an insert statement in my model I need.

$db->query("INSERT INTO test(id,name) VALUES("id","name")");

Now, with the Datamap class, it will be like

$datamap->create("test","id=id&name=name");

Below is snippet code from the Datamap class that I created.

    function create($tablename,$variables){
    $id=0;
    $tbl = $this->creturnval($variables);
    $tblVal = $tbl[0];
    $tblData = $tbl[1];
    $this->db->execute("INSERT into $tablename($tblVal) VALUES($tblData);");
    $id = $this->db->lastInsertedId();
    return $id;
}


function creturnval($variables){
    $vars = explode("&",$variables);
    $count = sizeOf($vars);
    $tblVal = "";
    $tblData = "";
    for($i=0;$i<$count;$i++){
        $d = explode("=",$vars[$i]);
        $tblVal.= $d[0].",";
        $tblData.= "'".$d[1]."'".",";
    }
    $tblVal = rtrim($tblVal, ',');
    $tblData = rtrim($tblData, ',');
    $return[0] = $tblVal;
    $return[1] = $tblData;
    return $return;
}

My concern is actually the performance issue. Previously in my model class, if I just used $db->query(), it seems to be faster because I do not have to go through 2 functions.

Now, in order to do an insert, I will need to parse the variables, split & etc, then process it.

My idea of using this Datamap class is actually to provide more maintainability and standardization. This is to prevent all my model classes from having sql statements over the place which looks untidy.

Do you think this will pose a possible performance issue?

PS: I am using my own framework that I build for my web application

Appreciate all advice.

  • 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-06-07T06:35:08+00:00Added an answer on June 7, 2026 at 6:35 am

    I think a more common way of writting SQL wrappers is like this:

    $item = $datamap->create("test");
    $item->setValue("id", $id);
    $item->setvalue("name", $name);
    $item->update(); // push to database
    

    $datamap->create(); return an object that will hold the values for a record. setValue and getValue allow you to access it. update pushes new values to the database. Similarly, you could implement $datamap->get("test", 1234); where 1234 is the id of the record you want to fetch. get returns the same object as create, with the same functions. update will then cause an UPDATE instead of an INSERT. After inserting a record using update you can use mysql_last_insert_id() to fetch the id and set it in the object so you can perform UPDATEs on it after that point. (The object has to keep track of it’s ‘state’).

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

Sidebar

Related Questions

I'm creating a class that can read from a dicom file. This is basically
I'm creating a class that will store data in a file and I need
I am creating a class that is used as an portal to read, insert
I'm creating a class that will be part of a DAG. The constructor will
I'm creating a class library that will be used in a web application. One
I'm creating a class using jsoup that will do the following: The constructor opens
I'm creating a class that will manage a connection to a Firebird database. The
I am creating a class that will handle mails and I am using PHP.
I'm creating a class called ImageLoader that will be used to load various image
I m creating a class that extends AlertDialog. and setting layout. But when pop

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.