user3698265
user3698265

Reputation:

how can get database name in wordpress?

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.

Upvotes: 7

Views: 10757

Answers (2)

Ravi Patel
Ravi Patel

Reputation: 5211

you can get anywhere your db name using

 <?php  echo DB_NAME; ?>

 <?php echo DB_USER; ?>

or

To get the db name using $wpdb:

global $wpdb;
echo $wpdb->dbname;

It will return database name as a string.

enter image description here

enter image description here

Upvotes: 9

nikunj gandhi
nikunj gandhi

Reputation: 779

You can get database name by DB_NAME constant.You can check by printing it

<?php echo DB_NAME; ?>

Upvotes: 1

Related Questions