[wp-hackers] Help with wpdb Class Errors
mike_walsh at mindspring.com
Mon May 11 10:15:05 GMT 2009
In the plugin I am working on I am using WP's wpdb database class to access
custom tables. From time to time, I run into a problem where creating a new
instance of a wpdb class fails and I am at a loss as to why.
This code fragment checks to see if creating a new instance works and if
not, dumps an error.
$this->wpstdb = new wpdb(WPST_DB_USERNAME,
WPST_DB_PASSWORD, WPST_DB_NAME, WPST_DB_HOSTNAME) ;
if ($this->wpstdb->dbh == false)
This is the error I get:
Error establishing a database connection
This either means that the username and password information in your
wp-config.php file is incorrect or we can't contact the database server at
localhost. This could mean your host's database server is down.
* Are you sure you have the correct username and password?
* Are you sure that you have typed the correct hostname?
* Are you sure that the database server is running?
If you're unsure what these terms mean you should probably contact your
host. If you still need help you can always visit the WordPress Support
The code always uses the same constants to connect to the database, they
come directly from wp-config.php.
Anyone have any suggestions on how to track this down?
Mike Walsh - mike_walsh at mindspring.com
More information about the wp-hackers