[wp-hackers] Using wpdb by inheriting the class
Chris Coggburn
Chris at Coggburn.us
Sat Jul 31 09:25:14 UTC 2004
I was talking with a C++ developer, and they sure are fond of OOP
programming, and they mentioned that the best way to access $wpdb would
be to define your own class for your plugin and then just inherit wpdb
into that class. This would allow you to add your own $tables to the
$wpdb class. Just wondering what the developers think of this, it has
saved me so much time and hack jobs so I am fond of it.
Example:
class someplugin extends wpdb {
var $newtablevar;
function someplugin() { // This calls the wpdb constructor to select
the db for access
global $loginsql, $passsql, $base, $server, $table_prefix;
$this->newtablevar = $table_prefix . 'NEWTABLENAME';
$this->wpdb($loginsql, $passsql, $base, $server);
}
function dosomething() {
echo $this->get_row('SELECT 'stuff' FROM $this->newtablevar WHERE id=1);
}
}
--
Chris Coggburn
http://noderat.com
http://chris.coggburn.us
http://beyonddigital.net
More information about the hackers
mailing list