I’ve been thinking of writing a Backend-End Admin Generator for a while now. But after some searching I still can’t find a solution to retrieve the relationships of the tables.
How would I go about retrieving any relationships that a table has in PHP, if this is even possible?
Update
What I want to achieve is to build a script that you point at a database. The script then lists all the tables in the database and allows you to created/edit/delete the records in these tables. But I would like to be able to find relationships and present the user with say a drop down box of all the values they can select. For example if the column “user” is linked to the table “users” on the column “id”. Then I would like to be able to recognize that and instead of asking you for a ID of the user allow you to select the user’s name from a drop down.
You won’t look for relationships in PHP. You’ll look for them with SQL statements submitted to the DB through PHP. Unfortunately, the exact queries you’ll needs will vary from database to database as every system names their system tables something different as well as storing the data differently (unless you’re going to build your system for one DB rather than something more robust).
Research the specific RDBMS in question for a way to view the SQL command used to build the tables in the schema, then just parse out the foreign key statements. Might be your best bet because the SQL commands to define them are fairly universal so you’ll get some portability.