|
Posted by distatica on 04/22/07 02:07
distatica wrote:
> Hello all,
>
> Let me first start by saying I am a PHP newbie, and this may be a
> pathetically easy question, I'm not sure.
>
> I am currently retrieving the latest YouTube videos that have been
> posted using Magpie RSS Libraries. The script I am writing must then
> take those entries and write the YouTube video id, video name,
> description and URL to a database for later use. I have a script that
> does that no problem; what I am having issues with is how to make sure I
> do not add duplicate entries to the database. At first glance I figured
> I could just query the MySQL database for each item in the RSS feed, and
> see if that Video ID was being used. While I'm sure this will work, it
> sounds like a lot of unnecessary php<->mysql interaction. My second
> thought was to insert the last known feed from the cache that Magpie
> creates into an array, and then the new feed that is fetched into an
> array, and then use array_diff() to compare them, but I'm not sure this
> will work as I intend. If anyone has experienced a similar problem, or
> has any tips for a newbie, I would greatly appreciate them.
>
> Thank you in advance for your time.
>
> Sincerely,
> distatica.
I just wanted to follow up with this, in the event that it should come
across a search somewhere. By setting the table column to a unique
constraint you will raise a mysql error if there is a duplicate entry.
In my case this was simply a matter of doing:
mysql> ALTER TABLE tablename ADD UNIQUE (columnname);
columnname of course being the column you want to reject duplicate
entries from being inserted.
Of course I welcome any new suggestions, corrections, or information.
Thank you kindly,
distatica.
[Back to original message]
|