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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:25:39+00:00 2026-05-27T18:25:39+00:00

I have a xml file which contains data I want to insert into a

  • 0

I have a xml file which contains data I want to insert into a mysql database. Now I allready have entries in my database, so these should be updated, not existing should be added and – now comes the problem – the entries which are in the database but not in the xml should be deleted. So what I tried is creating 2 arrays, one containing some comparison values of the xml data, so for example
$array_new["some1"] = "test";
$array_new["some2] = "test2";

and the other one containing the old data like $array_old["some1"] = "something"; $array_old["some2"] = "test2";

Now I would like to compare these 2 arrays and add all the values which are NOT in both to a new array. I tried using array_diff but this will only add the one value which is not in both arrays to a new array. But I need to have all the values which have the same key in a new array so I can delete them.

Anyone has any idea how to accomplish this? Thanks!

  • 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-27T18:25:40+00:00Added an answer on May 27, 2026 at 6:25 pm

    Assuming that your table has a unique index (primary key) and that your xml data has the same key data available, follow these steps:

    1) Delete all records from the table that aren’t in your array:

    DELETE FROM tablename WHERE unique_field NOT IN (<comma seperated list or keys>)
    

    2) Run a INSERT … ON DUPLICATE KEY UPDATE type query:

    INSERT INTO tablename VALUES (a, b, c) ON DUPLICATE KEY UPDATE field1 = a, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file which contains some data as given. <?xml version=1.0 encoding=UTF-8
I have a XML document which contains around 4000 entries of data. The data
Good morning. I have an XML file which contains lists of warning and errors
We have a PageRoles xml file which contains the page path and the user
I have a large XML file which in the middle contains the following: <ArticleName>Article
i have a log file which contains hundreds/thousands of seperate XML messages and need
Me again... I have an XML File that contains different categories which I would
I have an XML file which I'd like to parse into a non-XML (text)
I have a large raw data file (up to 1GB) which contains raw samples
i have file called data_out.xml which contains this xml code: <?xml version=1.0 ?> -

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.