How to access $wpdb?

I’m writing code in a kind-of standalone PHP file outside of a WP plugin.

How can I get access to $wpdb so that I can query the WP database?

$wpdb->get_results() is giving me …

Fatal error: Call to a member function on a non-object

I have even …


in top of PHP file.

you need to make it a new object,

$wpdb = new wpdb();