If you're loading it from a standalone PHP file (ie not from within your WordPress theme), you'll have to call wp-load.php
to initialise the WordPress variables (including $wpdb
). Have a look at this answer, including the comment about only needing wp-load.php
.
I'd consider using a relative path (what that would be would depend on where you put your page relative to WordPress) rather than using $_SERVER['DOCUMENT_ROOT'];
, but that's just a personal preference.
EDIT
Rereading after seeing your comment, I've just realised $wpdb->words
probably won't exist. Try
$words = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "words")
instead. That'll generate the table name correctly as wp_words
. Of course, you'll need to populate it the same way.