To get your WordPress database name with PHP inside a WordPress plugin or theme file, simply use this simple PHP code:
//Get the db name using $wpdb:
$deename = $wpdb->dbname;
echo “Your Database: $deename<br />”;
The first line, global $wpdb initiates the wpdb class in WordPress which has a lot of handy MYSQL database functions within WordPress. Learn more about wpdb HERE.