Re: Re: Sync CSV files with MySQL Database.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, May 11, 2013 at 9:41 AM, Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx> wrote:
> On 5/11/2013 12:57 AM, Carlos Sura wrote:
>>
>> Hello mates,
>>
>> Perhaps this seems to be a silly question, but it is not to me, here is
>> the
>> scenario:
>>
>> I know how to import CSV files with PHP to a MySQL database, the thing is,
>> that CSV file is automatically feed by a third-party application, I want
>> to
>> do something to add just the new records, not all the records again.
>>
>> Any idea or example, will be really appreciated.
>>
>> Thanks!
>>
> So - just how are you doing your import now?  If you are breaking down the
> csv "record" into fields before adding it to the db, then it would be simple
> to take the 'key' fields and check your database before adding each record,
> no?

While not strictly a PHP operation, you can compare two files and just
get the new lines in the second file using the comm(1) command in
shell:

$ comm -1 -3 file1 file2

will simply emit the lines in file2 that are not in file1

If you keep around the last file loaded, and compare it using the
above command with the newest file, you'll just have the new records
to import. Then keep the newest file to compare with the next newest
one.

If you want to keep things all pure PHP, you could easily come up with
a similar operation in PHP.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux