Aamir Mahmood
Aamir Mahmood

Reputation: 2724

How to check which columns and tables are used in PHP App

Okay, I know this i kinda a vague question. But I have a requirement where I need to list all the tables and the columns which are not being used in the application. I can do manual code search but that would take so much time. The number of tables to check are 140 and maximum number of fields in a table are 90.

Right now I have started searching the code for table names, and I have created an excel sheet with all the table names, and when I found a table in code I highlight that in green. So tables are bit easier.

My question really is, is there a way to speed up this process? or some methods / techniques can be applied?

Thank you?

Upvotes: 0

Views: 77

Answers (2)

m4t1t0
m4t1t0

Reputation: 5721

I suggest you to build a script that perform the job. For example, you can optain the table list in a database with a query like this:

show tables from YOUR_DATABASE;

More info: http://dev.mysql.com/doc/refman/5.0/en/show-tables.html

And then you can loop your tables and check for fields using:

show columns from YOUR_TABLE;

More info: http://dev.mysql.com/doc/refman/5.0/en/show-columns.html

Finally you can search (grep for example) your tables and fields in your code and write a log or something similar.

Upvotes: 1

Palantir
Palantir

Reputation: 24182

All depends on your app size and the coding technique.

If I had a large application, I would enable full mysql log (or hack into any database wrapper I may have, to log the queries), run the application, and then extract the information from the log. However, doing so you are just moving the problem. Instead of worrying to capture all the queries, you now need to ensure to run each and every line of your application code (so you are sure that nothing escaped and that you have analyzed all the possibilities).

This is in fact called "code coverage analysis" and there are tools which will help you with that.

This said, I believe that the manual analysis may be quicker for small applications.

Upvotes: 1

Related Questions