1 Jul 2006 01:09
Re: Update or add?
Venkat Venkataraju <outofjungle <at> gmail.com>
2006-06-30 23:09:12 GMT
2006-06-30 23:09:12 GMT
Hi All, there is not-so-used format of SQL format that is INSERT INTO table SET col1=data1, col2=data2... ON DUPLICATE KEY UPDATE col1=data1, col2=data2...; you have to define a primary or unique key in the table and all will work well. for more info http://dev.mysql.com/doc/refman/4.1/en/insert-on-duplicate.html Cheers /V Brian Dunning wrote: > I have a table where I want to update each record with today's date as > it's hit, or add the record if it's not in there: > > +------+-----------------+------------+ > | id | creation_date | last_hit | > +------+-----------------+------------+ > > I'm trying to do this with a minimum of hits to the db, so rather than > first searching to see if a matching record is in there, I thought I'd > just go ahead and update the matching record, check to see if it failed, > and if it failed then add a new one, like this: > > $id = $_GET['id']; > // Update(Continue reading)
RSS Feed