is there a tool or any quick way to extract db tables automatically from my php codes?

Viewed 40

I recently started to re-engineer a PHP-mysql project which was created about 7 years ago. I have only php and html codes and no mysql database or any document which shows the database structures.

Is there any tool which help me extract the tables of my database using php files? in the php files i have insert queries and select queries and also update.

I think of a tool (such a crawler) which takes my php files as input and create some sql create table queries as output.

1 Answers

I'm afraid there is no such tool. There's no guarantee that your PHP code even makes reference to every table or every column. You might see code like this:

mysqli_query("INSERT INTO mytable VALUES ('1234', 'abc', NULL, DEFAULT)");

What are the column names? What are their data types? Is the first column an integer, or is it just the developer's habit to put numbers inside string delimiters? What's the default value referenced by the fourth column? How could an automated tool infer these things by scanning this code?

Many details such as triggers, constraints, and indexes, are not referenced at all by PHP code, but they're necessary to make the application work.

If the database has any stored procedures, the PHP code wouldn't have any knowledge of the logic inside the procedure.

mysqli_query("CALL myprocedure(1234, 'north')");

The same problem exists for the query in VIEW definitions.

Reverse engineering this project is going to be a time-consuming forensic task, plus a lot of guesswork.

It really illustrates the importance of including the current schema dump with the source code of a project.

Related