rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
This is more of a MySQL question, but I am sure someone out there will know an answer.
Is there and easy way to insert/update a record in a mysql table depending upon whether or not the record exists?
i.e.
if ($id exists in table) { update field=value where id=$id } else { insert into table id=$id, field=$value }
Hope that makes sense :)
At the moment I am doing a select and then using a perl if statement to determine if it should update or insert.
But I am sure there must be an easier way for such a common thing.
Any help would be appreciated.
Cheers,
Reagen
Is there and easy way to insert/update a record in a mysql table depending upon whether or not the record exists?
i.e.
if ($id exists in table) { update field=value where id=$id } else { insert into table id=$id, field=$value }
Hope that makes sense :)
At the moment I am doing a select and then using a perl if statement to determine if it should update or insert.
But I am sure there must be an easier way for such a common thing.
Any help would be appreciated.
Cheers,
Reagen
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: mysql insert/update
by liz (Monsignor) on May 31, 2004 at 10:05 UTC | |
by rsiedl (Friar) on May 31, 2004 at 10:57 UTC | |
by Anonymous Monk on Dec 07, 2008 at 13:58 UTC | |
Re: mysql insert/update
by Happy-the-monk (Canon) on May 31, 2004 at 10:03 UTC | |
Re: mysql insert/update
by dkr (Initiate) on May 31, 2004 at 22:46 UTC |
Back to
Seekers of Perl Wisdom