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.

I'm querying the postmeta table to see if a url has already been entered, using this statement (where $thisLink is the url I'm checking)

  $mypostids = $wpdb->get_results("select * from $wpdb->postmeta where meta_key = 'rssmi_source_link' and meta_value like '%".$thisLink."%'");

The problem is that on some servers it appears it's not finding urls that already exist in the database, and I'm becoming convinced that this may be due to the server failing on the query or something like that.

Anyway, I'm not sure how to check for both the url already exist (thus don't process anymore) or there was some sort of failure in completing the query). right now, I just use:

if (empty( $mypostids )){ do stuff}

is there a way I could make the condition like if empty AND if not a failure then do stuff?

share|improve this question
    
What is "not a failure"? I use empty all the time because it returns false for all kinds of values. It looks to me like it should work the way you want it too. –  s_ha_dum Jan 15 '13 at 1:48
add comment

1 Answer 1

You test for a fail by explicitly testing for false:

if (null === $mypostids) { /* it failed */ }

NB: three equals signs! you want to check for identical, not just equivalent

edit: originally said false, changed to null after looking at get_result() function in source.

share|improve this answer
    
empty already does that. –  s_ha_dum Jan 15 '13 at 1:46
    
OP wants to know how to differentiate "no rows found" (which is an empty array) from "error" (which is null -- got it wrong above). Why is up to them, frankly. –  webaware Jan 15 '13 at 1:59
    
That is not how I interpret "empty AND if not a failure", but maybe you are right. It isn't quite clear. –  s_ha_dum Jan 15 '13 at 2:01
    
Thanks...I'll try that test for fail along with the empty. –  Allen Jan 15 '13 at 2:08
add comment

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.