Reputation: 332
I need to write a code that finds the name of the current sql database and puts that name in a variable. I'll take any suggestions, but what I was thinking was querying the current database name and putting that in a variable. I don't know if that will work because I can't seem to query my database name at all. The database I'm using for this is named "wp_plugin_development" but the query won't show me that. I'm using the code:
SELECT DB_NAME() AS [Current Database];
to get the database name in phpMyAdmin, but it brings up an error saying:
1305 - FUNCTION wp_plugin_development.DB_NAME does not exist
I don't know why it's doing that. Thanks for any help.
Upvotes: 0
Views: 973
Reputation: 11
SELECT schema();
can be used to retrieve the current db name in Mysql. this can also be assigned to a variable using AS keyword.
Upvotes: 1
Reputation: 284
If you are using MySQL try:
SELECT DATABASE();
or refer to this:
Upvotes: 3
Reputation: 27092
The WordPress database name is already stored as a constant in a standard wp-config.php. You can access it with DB_NAME
.
<?php $database_name = DB_NAME; ?>
Upvotes: 2