Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

perl

dbi

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?

like image 354
Harry Avatar asked Nov 21 '08 05:11

Harry


1 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.)

like image 128
Rizwan Kassim Avatar answered Sep 17 '22 18:09

Rizwan Kassim