My WordPress plugin code looks like this:
$table = $wpdb->prefix."cf_form_entry_values";
$where = "entry_id = ".$entryid;
$select = "SELECT id FROM {$table} WHERE {$where}";
$query = $wpdb->prepare( $select );
$result = $wpdb->get_results( $query );
It produces the following mysql query: SELECT id FROM wpqs_cf_form_entry_values WHERE entry_id = 49
WordPress returns an empty array. No SQL errors reported (I have show_errors() set), var_dump is empty. But if I cut and paste that query into phpMyAdmin it returns the expected rows. I don't understand why WordPress is giving me empty results. I've also tried SELECT * FROM wpqs_cf_form_entry_values WHERE entry_id = 49
I've noted that if I remove the WHERE clause, WordPress is happy to return the entire table to me, but why can't I filter it with a WHERE clause?
MORE INFORMATION AFTER FURTHER TESTING ... It's curious what works and what doesn't.
These two queries don't work:
SELECT * FROM wpqs_cf_form_entry_values WHERE entry_id = 55 AND slug = 'photo'
SELECT * FROM wpqs_cf_form_entry_values WHERE entry_id = 55
But this one does:
SELECT * FROM wpqs_cf_form_entry_values WHERE slug = 'photo'
I've tried putting the entry_id value in quotes and without. Does that extra info help anyone?