Show Current Database in MySQL

Oct 13th, 2009

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:
db_name2.tableName

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()".

<?php
mysql_query("select database()");
?>

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

mysql_query("show databases");

 

 

Possibly Related posts:

  1. No comments yet.
  1. No trackbacks yet.

All comments will be moderated.