1

Is there a way to get the database metadata using PHP's PDO.

I'm looking for something similar to the Java JDBC DatabaseMetadata Interface.

What I'm interested in is to retrieve the list of foreign keys of a given table, but I don't want the solution to be bound to any specific DBMS.

What I found so far is the information_schema which is ANSI/ISO SQL:2003 standrad and stores these metadata but I'm not sure all RDBMSs comply with it and generally an SQL free solution (like JAVA DatabaseMetadata) would be preferable.

Thanks for any input,

Memos
  • 464
  • 3
  • 9

2 Answers2

0

I'm not sure if they are equal but for mssql you have also a information_schema, and i don't know if other DBMS also have the same schema

http://msdn.microsoft.com/en-us/library/aa933204%28SQL.80%29.aspx

Also you got these to provide information about your database structure

http://dev.mysql.com/doc/refman/5.0/en/explain.html

http://dev.mysql.com/doc/refman/5.0/en/show-index.html

But this doesn't work for all other DBMS again (JDBS uses desc instead of DESCRIBE)

So i guess there is not a single/consistent way to retrieve database structures for multiple DBMS, maybe you can extract the structure not from the database but from your models in your application?

Sander Visser
  • 4,144
  • 1
  • 31
  • 42
0

This does seem to be rather a serious thing to be lacking from PHP PDO... and getColumnMeta is still "experimental".

Just a thought: it's hardly elegant, but it may be something to think of in extremities, where you really really want or need as much of this dbase or column meta data as poss: use PHP exec() to run (for MySQL):

mysqldump -d -h localhost -u username -ppwd databasename > dumpfile.sql

and then examine dumpfile.sql. Obviously you'd have to find similar commands for other DBMS's...

mike rodent
  • 14,126
  • 11
  • 103
  • 157