Solution:
You are quite possibly missing the global declaration of $wpdb
.
From the wpdb reference.
WordPress provides a global variable, $wpdb,
which is an instantiation of the class already
set up to talk to the WordPress database.
Always use the global $wpdb variable.
(Remember to globalize $wpdb before using it in any custom functions.)
You need to use it like this.
global $wpdb;
//do something with it.