- You need to globalise the variable
$wpdbby addingglobal $wpdb;before you do anything.
- If you are trying to access a custom table (created by a plugin or something else) you must add the name of the table to the
$wpdbobject:
$wpdb->nameofyoucustomtable = 'wp_nameofyoucustomtable'; // you may not need the wp_ if you arn't using a wordpress table