Show Current Database in MySQL

How to know which database is in use currently? For using a particular database, MySQL has <code>Use </code> statement. After you execute USE statement, by default all the query will be executed against the database mentioned in USE statement.

Use database_name;

For using other database after this statement, you can write add database name before table name:

Now, this USE statement is issued deep inside a badly written script and you do not want to bother searching deep inside code for knowing the current database in use. For that just issue -
"select database()".

mysql_query("select database()");

For getting the list of database, you have access to, issue
"show databases".

mysql_query("show databases");