? updating records in DB from a text file

Discussion in 'PHP' started by gemini, Apr 17, 2006.

  1. #1
    Hello everyone!

    Is there a way to update records in a database from a text file?
    Let's say I have an inventory database and I get most current inventory in a TXT file every day. I automatically drop all the records in DB and import the whole new thing from the text file. It works fine for me right now, but in order to monitor changes I would like to be able to update only changed records in the database, delete those that are gone and insert the new ones - this way by adding additional tracking fields I can monitor changes in the inventory. So, how do I update my database in that way from the TXT file I've got? Any hints or where to look would be nice.

    Thanks!
     
    gemini, Apr 17, 2006 IP
  2. mnemtsas

    mnemtsas Super Dud

    Messages:
    497
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try looking at the fopen and feof functions in the PHP reference. There's some stuff in there about opening CSV files and such like. I do something similar to this using CSV files on a user database here at work.
     
    mnemtsas, Apr 17, 2006 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If your DB understands SQL, you can try the insert on duplicate update syntax.
     
    exam, Apr 17, 2006 IP
  4. gemini

    gemini Peon

    Messages:
    256
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the fast reply guys!

    ON DUPLICATE KEY UPDATE sounds interesting. Not sure if it will work if I have more fields in the database then in the text file - I need to look more deeply into it.

    Thanks for your help :)!
     
    gemini, Apr 17, 2006 IP