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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:54:05+00:00 2026-06-15T16:54:05+00:00

I have 2 databases on 2 different servers. The source database is a massive

  • 0

I have 2 databases on 2 different servers. The source database is a massive real estate database and the second is a WordPress database. I have to import the data from the source to the WordPress database’s posts and postmeta tables.

Currently, I’m pulling everything out of the source db and then looping through those results to insert them into the posts table with another nested query to insert each field as a metavalue using the insert id from the post insert. In other words, it’s a memory hog.

My question is, can the loop I have below be improved so that there aren’t so many individual insert lines? Or does anyone have any suggestions for making this faster / not as sloppy?

// SOURCE DB
$query = "select $fields from listings where data_id = 'B'"; 

$result = mysql_query($query);

// WORDPRESS DB
while ($row = mysql_fetch_assoc($result)) {
    $query2 = "insert into wp_posts (post_author, post_content, post_title, post_status, comment_status, ping_status, post_name, post_type) values";
    $query2 .= " ('1', '" . mysql_real_escape_string($row['remarks']) . "', '{$row['mls_acct']}', 'publish', 'closed', 'closed', '{$row['mls_acct']}', 'properties')";

    $result2 = mysql_query($query2);

    $id = mysql_insert_id();

    foreach ($row as $key => $val)
    {
        $query3 = "insert into wp_postmeta (post_id, meta_key, meta_value) values ";

        $query3 .= "('$id', '$key', 'mysql_real_escape_string($val)')";

        $result3 = mysql_query($query3);
    }
}
  • 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-15T16:54:06+00:00Added an answer on June 15, 2026 at 4:54 pm

    The first thought I have on this is to insert the records in batches rather than one at a time. So your inner insert would end up being something like:

    insert into wp_postmeta (post_id, meta_key, meta_value) values
    (1, meta_key_1, meta_value_1),
    (1, meta_key_2, meta_value_2),
    (1, meta_key_3, meta_value_3),
    (1, meta_key_4, meta_value_4),
    (1, meta_key_5, meta_value_5),
    (1, meta_key_6, meta_value_6),
    (1, meta_key_7, meta_value_7),
    ...
    (1, meta_key_100, meta_value_100);
    

    I’m not sure what’s the optimum number of records per batch, but I think you get the idea.

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

Sidebar

Related Questions

I have an ETL application which extracts data from a source database (for which
I have 2 data contexts in my application (different databases) and need to be
Basically I have 2 SQL queries from 2 different databases and I am trying
I have 2 sites that are the same, but different databases and data. One
I have to query two different servers from a dynamically built query. It basically
I have a database where I store two different kinds of data. One table
I have a server with a PHP script that pulls data from a source
I have found a way to make two tables from different databases match each
I have two SQL Server databases with identical schemas, but different data. I also
I have a screen where a user selects database source from a drop down.

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.