Hi! Sorry for my ugly English. I use mysql in my PHP script(for calculating INs and OUTs from site). And I meet some strange thing there.
Example goal: store statistics for clicks on some links. I use next algorithm: --- $key='somekeyvalue'; dbquery("update sometable set count=count+1 where keyfield='$key'"); if(mysql_affected_rows()<1) dbquery('insert into sometable set keyfield='$key', count=1'); --- First question: this is good method? Or I MUST use pre-query with "select count(...) from sometable where keyfield='$key'" for detection: exists needle record(for update) or not(for insert)??? Second... My script work on many different hosts with different hardware, os(only Linux or FreeBSD), and different PHP and MySQL version. It works fine excepting one thing... Sometime happens errors like: MySQL: Duplicate entry 'somekeyvalue' for key 1, query was: insert into sometable set keyfield='somekeyvalue', count=1 Why this happens? On some hosts this messageis very rare, but on others - so often... I cant understand reason :( My script use DB locks, so two clients cant make this situation(i think). Only one idea: sometime 'update' query dont work(or work, but dont return good result), and 'insert' query started... But WHY? Help me plz. Thnx. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]