is it possible to query pdo object for database file name ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
madrazel
Forum Newbie
Posts: 7
Joined: Wed Sep 09, 2009 9:24 am

is it possible to query pdo object for database file name ?

Post by madrazel »

in php I declared database object:

Code: Select all

$pdo = new PDO('sqlite:mybase.DB3');
i know how to get information about engine used in this connection, which is:

Code: Select all

$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);  // ---> string 'sqlite'
But I do not know how to get back the actual database file name (that is 'mybase.DB3') back from this object. Is it possible to be done from query to the database itself (maybe some kind of PRAGMA) or from query to the object.
User avatar
Zyxist
Forum Contributor
Posts: 104
Joined: Sun Jan 14, 2007 10:44 am
Location: Cracow, Poland

Re: is it possible to query pdo object for database file nam

Post by Zyxist »

AFAIK there is no method or attribute that returns the PDO DSN. However, is it a problem for you to store it in some variable and access it through it? I'd do that in this way.
madrazel
Forum Newbie
Posts: 7
Joined: Wed Sep 09, 2009 9:24 am

Re: is it possible to query pdo object for database file nam

Post by madrazel »

The solution is to query the database itself:

Code: Select all

PRAGMA database_list
Post Reply