Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to get WordPress database name. I have also try to get database name from $wpdb but failed. When print the $wpdb it give an object array but i don't know how to get database name from object array.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

To get the db name using $wpdb:

global $wpdb;
echo $wpdb->dbname;

It will return database name as a string.

share|improve this answer
Thanks @The Sufi – user3698265 Jun 2 '14 at 6:38

You can also get the database name from the constant DB_NAME without going for $wpdb.

share|improve this answer
This is best answer. – ahmetlutfu Jun 2 '14 at 9:38
what scope do you need to be in, or what library or object do you need to load in order for DB_NAME to be recognized, and not be an uninitialized constant? – ahnbizcad Sep 13 at 23:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.