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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:40:53+00:00 2026-05-30T09:40:53+00:00

I’m currently trying to write a simple ORM with PHP and mysql. I want

  • 0

I’m currently trying to write a simple ORM with PHP and mysql. I want the orm class to be able to work with joined tables.
So here’s my problem, the following code shows how I map the data the query yields into an array.

public function execute_query($db_connection)
{
    $query = '';

    foreach($this->sql_query as $query_part)
        $query .= $query_part;

    $result = $db_connection->query($query);
    while($row = $result->fetch_assoc())
    {
        array_push($this->m_Data, $row);
    }
}

db_connection is a mysqli object.
sql_query contains all the different query parts (e.g. sql_query[‘join’] etc.).
m_Data is the array that contains the data read from the db.

My specific problem now is when I’m using a join statement in my query this function will just override fields with the same name in my m_Data array. Also if I dont save the name’s of the table the specific field data is coming from, I later can’t update the tables with the same join statement.

tl,dr. I need to be able to not only save the table data like this: m_Data{ ‘field_name’ => ‘value’ } but I also need to save the table name the field is selected from. I could then save the data like this m_Data{ ‘table_name.field_name’ => ‘value’ } which enables me later to generate a query to update the joined tables successfully.

I cant seem to find any information on how to get the origin table name for each field I pull out of the result.

If it isnt possible with mysqli I’d much appreciate it if you point me in the right direction.

extra short problem statement:
I need to get a result set and read each row seperatly. For each row I need the following information for every field selected: field_name, table_name, value.

There must be a simple answer to this but I seem to be searching for the wrong keywords to find a solution.

I hope I’ve written this understandable enough.

  • 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-30T09:40:54+00:00Added an answer on May 30, 2026 at 9:40 am

    Seems to me that you should store table column values in an object, so if you have a related table, the column values would be stored in a separate object – and so would not interfere with the values in your primary table.

    In general you might work with the ORM this way:

    // Make joined query
    $rows = ...
    
    foreach($rows as $row)
    {
        // $row just refers to the primary table
        echo $row->id;
    
        // You get a many:1 related table this way
        echo $row->getRelatedRow()->value;
    
        // You get a 1:many rows this way
        $rows = $row->getOtherRelatedRows();
    }
    

    Depending on how you set up your query options, getting related data may or may not initiate further SELECTs to get the required data.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.