[thelist] insert if select fails to find element

Joshua Olson joshua at waetech.com
Thu Nov 17 04:43:41 CST 2005

> -----Original Message-----
> From: Alex Beston
> Sent: Thursday, November 17, 2005 1:53 AM
> ""INSERT into word_list(word) VALUES ('$word')" IF ('$word') 
> something like that. so have one query rather than two.


Here's a proven technique:  

Assuming that you have some sort of constraint on the table that checks for
uniqueness for the field "word", simply do an INSERT.  If the INSERT errors,
check the error to ensure that the error indicates a constraint issue.  If
the error is regarding constraints, then continue to the next word..
otherwise error out.

Joshua L. Olson
WAE Tech Inc.
Phone: 706.210.0168 
Fax: 413.812.4864

Monitor bandwidth usage on IIS6 in real-time:

More information about the thelist mailing list