Application for PHP Documentation of Tables
March 26, 2010 11:51 AM   Subscribe

Looking for an Application to search a file directory which contains php files (or any code, if it will work with PHP) and find all of the Database Tables which are referenced in the code, without relying on comments in the Code.
posted by jesirose to Technology (5 answers total)
Not sure I follow. You're basically just doing a text search to find files which contain particular strings (i.e., the names of the tables)?

That's both a trivial and an esoteric need, so I doubt there exists a dedicated application for it. Should only take an experienced PHP programmer a few minutes to knock together a script that will do it. I'm a freelancer; memail me if you have money :)
posted by ixohoxi at 1:14 PM on March 26, 2010

No, an application which will find any table names. Not by a list of what tables we know we have, but a list of any tables referenced in the files. We have over 500 tables, I could run a grep on each of the table names but the boss asked for something more flexible and not manual.
posted by jesirose at 1:21 PM on March 26, 2010

The problem is that SQL queries are often generated dynamically. It's pretty rare to see a line of source code that contains a complete and valid SQL query that doesn't reference a bunch of variables.

Your best bet is to look for (or grep) any instances of 'mysql_query(' in your code, and then figure out what your query string is in each case. You'll have to do this by hand.

Also, given that you've very obviously got code spaghetti, you should start planning to rewrite your application. 500+ tables is absurd. I hate to sound like a snob, but there's no way you're ever going to be able to adequately document or maintain a system with such a level of complexity, unless you've been thoroughly documenting the development process since the beginning (which sounds unlikely from your post).
posted by schmod at 1:37 PM on March 26, 2010

LOL, I assume you've never worked as an employee, just a freelancer.

Obviously this is MY project which I KNOW was done PERFECTLY. It's not at all possible a large company needs a large database.

/end sarcasm here.

I'm just a contractor, and this app has been in place and working for I-have-no-idea-how-many-years. Most of the files have javadoc style comments. I was asked to see if something exists, not asked how to completely rewrite their entire system.

I told him we could write something ourselves to parse it, and they already have done but it just checks the comments.
posted by jesirose at 2:04 PM on March 26, 2010

I don't think this is possible, given how PHP works. Like schmod said, the vast majority of SQL queries are written dynamically. Even searching for mysql_query won't work, because it's most likely got a wrapper class around it of some sort (or it should, with an application of that size.) Everything ought to be abstracted by variable names and dynamically-generated strings up the whazoo. You'd almost need a PHP-interpretor app of some sort to accurately trace all the variable names back.

If I really, really needed something like this, I'd turn MySQL logging on (or the logging of what ever DB you're using), and log every query that's run. (Of course, this comes with a huge performance price; hopefully you've got a development environment.). Then test the crap out of the application, making sure to hit every possible use case and edge case, etc. Finally, parse the log of sql queries for the table names.
posted by cgg at 2:19 PM on March 26, 2010

« Older There is really no way to fix this, is there?   |   Help Me Name My Band's Music! Newer »
This thread is closed to new comments.