WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
    
$wpdb->dbname is a protected property: you shouldn't read it. Use DB_NAME constant instead, as @chittaranjan suggested. – Andrea Sciamanna Feb 26 at 11:26
    
@AndreaSciamanna what is wrong using $wpdb->dbname? Would you please care to explain? That will be helpful. – тнє Sufi Feb 26 at 15:10

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 '15 at 23:33

Your Answer

 
discard

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.