Page 1 of 1

Check if Table Entry Exists

Posted: Thu Aug 12, 2010 7:50 pm
by Jesse B
This seemed to be a very simple thing to do at first, but is proving to be more difficult than I originally imagined. I'm sure it's quite simple, I just can't quite figure it out. Every piece of code I've tried doesn't quite work properly. Anyways, I digress.

This is for an updating script that I wrote, which does a recursive scan and if it's a file, adds it's Path, Name, and Extension to a mySQL Table. Right now I've got it so it uploads an entry for each file, but if I run it again it adds a duplicate entry. I don't want to just wipe the table each time, as I'd like for the ID# in the table to remain the same.

Anyways, any suggestions? If you want my current code just lemme know and I'll post it.

Thanks,


- Jesse

Re: Check if Table Entry Exists

Posted: Thu Aug 12, 2010 10:42 pm
by requinix
Make the path+name+extension a unique key and use an INSERT IGNORE query.

Re: Check if Table Entry Exists

Posted: Thu Aug 12, 2010 11:29 pm
by Jesse B
I'll try that out, thanks.