Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there an equivalent to INSERT IGNORE in the wpdb class? As I'm fetching and inserting a twitter feed and the field in which I store the tweet ID is keyed UNIQUE, I am aware that duplicates are going to occur and do not need Wordpress informing me of them in my PHP error log. (Note, I would write the query I need and $wpdb->prepare it, but for whatever reason, that throws a bunch of other errors [that I'd be happy to share though don't consider them relevant to this question]).

share|improve this question
3  
You could try to update first and then insert if nothing was updated. Or if you want a single SQL command: INSERT ... ON DUPLICATE KEY UPDATE ... –  birgire Apr 18 '13 at 14:43
    
Thanks for your input. Just out of curiosity, why was your comment upvoted? Is INSERT IGNORE not the done thing? –  Evan Rose Apr 18 '13 at 17:51
    
"ignoring errors" should be avoided in general, better to take care of it if you can - is my advice ;-) –  birgire Apr 18 '13 at 18:11

1 Answer 1

up vote 1 down vote accepted

To answer the question directly, there is $wpdb->update but nothing that will strictly duplicate INSERT IGNORE that I know of. If $wpdb->update, does not work I am fairly sure that you will need to write your own query and use $wpdb->query and $wpdb->prepare.

share|improve this answer
    
Thank you for your answer. I am obviously trying to do things the Wordpress way, but as I said, I'd tried writing my own query and using query and prepare. THAT SAID, I did NOT do things the Wordpress way when I'd tried that previously in that I was preparing incorrectly! Writing my own query and correcty passing an array of my $vals quieted Wordpress down. Thanks again. –  Evan Rose Apr 18 '13 at 15:21
    
Oh and thanks for marking up my post ;) –  Evan Rose Apr 18 '13 at 17:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.