One note to add: you cannot use global inside a class, and of course you must use global to make your objects work with $wpdb .
While you cannot use global directly inside the class, you must declare $wpdb as global inside the function inside the class, and that works.
eg. This gives you an error message:
class wpdb_test { global $wpdb;
Because global cannot be used directly inside a class. Similarly, just referring to $wpdb inside the class, you also get an error message because the object does not know what $wpdb . You must declare $wpdb as global inside a function inside your class.
eg. This works great:
class wpdb_test { public $variable_name; public function __construct () { global $wpdb;
... and because $wpdb declared global inside a function inside a class that you can use.
RalphTheWonderLlama
source share