Would it be nice if the 2 queries of "check" + "insert" are replaced by one single "insert if not exists" query? This article may help us achieve this goal: http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html