rubing Posted October 27, 2008 Share Posted October 27, 2008 hi, i need help with a query. I want to change the following query, so that will not insert duplicate entries for records that have: (ip AND port) of an already existing record. INSERT INTO ProxyList (ip,port,speed) VALUES ($ip,$port,$speed); Quote Link to comment https://forums.phpfreaks.com/topic/130344-solved-insert-partial-unique/ Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 2 options: 1) Do a SELECT first to see if the row exists 2) Add a UNIQUE constraint to the table. Then, when you try to do the INSERT, it will just fail Quote Link to comment https://forums.phpfreaks.com/topic/130344-solved-insert-partial-unique/#findComment-676075 Share on other sites More sharing options...
lampstax Posted October 27, 2008 Share Posted October 27, 2008 3) Add an ON DUPLICATE part into your INSERT .. you'll still need some unique constraint on your table Quote Link to comment https://forums.phpfreaks.com/topic/130344-solved-insert-partial-unique/#findComment-676111 Share on other sites More sharing options...
rubing Posted October 27, 2008 Author Share Posted October 27, 2008 great ideas, i like them all I ended up making a unique index as per instructions here: http://www.gsdesign.ro/blog/mysql-make-a-combination-of-2-columns-unique/ Quote Link to comment https://forums.phpfreaks.com/topic/130344-solved-insert-partial-unique/#findComment-676118 Share on other sites More sharing options...
rubing Posted October 28, 2008 Author Share Posted October 28, 2008 This was a bad idea! Now, I am receiving an error whenever I try to insert a duplicate: Exception: Duplicate entry '3359686450-3128' for key 2 in /home/bob/public_html/blahalha.com/public/blahah.php on line 70 Quote Link to comment https://forums.phpfreaks.com/topic/130344-solved-insert-partial-unique/#findComment-676287 Share on other sites More sharing options...
rubing Posted October 28, 2008 Author Share Posted October 28, 2008 ok, just used 'INSERT IGNORE' and its fixed! Quote Link to comment https://forums.phpfreaks.com/topic/130344-solved-insert-partial-unique/#findComment-676289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.