On 5 May 2010, at 11:08am, yogibabu wrote:

> in php I declared database object:
> $pdo = new PDO('sqlite:mybase.DB3');
> 
> i know how to get information about engine used in this connection, which
> is:
> $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);   ---> string 'sqlite'
> 
> But I do not know how to get back the actual database file name 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.

It is indeed.  Check out 'PRAGMA database_list' in this page

http://www.sqlite.org/pragma.html

However, there's one caveat: you may or may not get back the name you used when 
opening the database in the first place.  Some filenames are aliases or 
pointers to other files.  And sometimes a file path gets expanded or otherwise 
interpreted when used (e.g. the use of '~' for the home folder.  So if your 
code is sensitive to either of these you may have to figure out how your 
particular installation of PHP is doing things.

>From a brief look at the PDO documentation you're right: the PHP PDO system 
>has no method of returning the name of the database.  This may be because many 
>database systems keep the information for one database in many different 
>files.  For instance, MySQL makes a folder with five files in before you've 
>even created your first TABLE.  And some systems don't keep separate databases 
>in a trackable way anyway: they really just keep all their databases in an 
>internal 'black box'.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to