I am writing a function to query some information from a custom table in the database. It seems that I am unable to query the database on the field I need.
function ch_details_from_id($id) {
global $wpdb;
$details = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ch_guests WHERE key = '" . $id . "'", ARRAY_A);
return $details;
}
$id is currently '001'. If I search on any other field in the table, I get the expected results, but on this field nothing is returned.
If I run exactly the same query in phpMyAdmin, it works fine.
"SELECT * FROM " . $wpdb->prefix . "ch_guests WHERE key = '" . $id . "'"
query in your phpmyadmin, if possible, that will give you clear idea about the problem.