How can I get the database name from a Perl MySQL DBI handle?

I've connected to a MySQL database using Perl DBI. I would like to find out which database I'm connected to.

I don't think I can use:

$dbh->{Name}

because I call USE new_database and $dbh->{Name} only reports the database that I initially connected to.

Is there any trick or do I need to keep track of the database name?

Answers


Try just executing the query

select DATABASE();

From what I could find, the DBH has access to the DSN that you initially connected with, but not after you made the change. (There's probably a better way to switch databases.)


Need Your Help

SQLAlchemy - AttributeError: 'Table' object has no attribute replace

table replace sqlalchemy attributeerror unicode-escapes

I am trying to extract schema from a table in one database and transfer it to another database. The following is a portion of the function which performs this operation.

How to create connection with the database in another computer using a SQL Server database?

c# sql-server

I am creating a network based application client will be using the data from the database which is in server computer so I want to create a SqlConnection with the database on the server computer so...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.