Jump to content

Reverse Engineer a MySQL Database/Table from PHP source files?


edwardcox

Recommended Posts

Hello All, first time poster long time reader. Perhaps what I am seeking is a little odd, however I am certain that it's been done before (somewhere).

I have the task of resurrecting a php project using MySQL database - however the project did not include a MySQL SQL dump file so that I can easily recreate the Database/Tables. So, I am wondering if anyone has come across a tool or code that will allow me to point to the source code files in a directory and then rebuild the Database/Tables from the SQL code in the PHP source code? Does that make sense? I hope so. It's a fairly hefty project with several dozen .php source files and so I would like to try avoiding a manual line by line code inspection and hand coded MySQL rebuild.

Any suggestions? (I will, if I may, cross post this to the PHP help area as well.).

 

Kind Regards,

 

Ed Cox

edward.cox02@gmail.com

Link to comment
Share on other sites

edwardcox, I posted in the duplicate topic you started in MySQL Help.  Depending on how big the DB is, which you don't know because it's gone, creating it manually with logic may be faster than creating a custom tool.  It may get very messy and frustrating.

Link to comment
Share on other sites

  • 4 years later...

Hello Si-Fu, sorry this is an old thread ::) ,

 

my question wich is similar : is it possible to recreate the database with this query please ?

 

exemple:

 

$user = $remotedb->query( "SELECT * FROM user WHERE email = '".$_POST['email']."' LIMIT 0,1", 41, __FILE__, true );

 

 

i would like to know if there is a sql fonction that can export the result for recreate the database if the query succefully get the request

 

thanx you

Link to comment
Share on other sites

If you have or have access to the actual database, you can use any database management tool to get a .sql dump that would contain the table structure(s).

 

If you can execute select queries, you can use a SHOW CREATE TABLE tbl_name query to get the table structure.

 

After performing a query, you can access the meta data returned by that query using functions like - mysql(i)_fetch_field(s)

Link to comment
Share on other sites

is it possible to help me to recreate the table for this query please ?

"SELECT * FROM user WHERE email = '".$_POST['email']."' LIMIT 0,1", 41, __FILE__, true );

 

here is the query i have create grabbing some code :

 


CREATE TABLE IF NOT EXISTS `user` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(80) NOT NULL,
`password` char(41) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

 

INSERT INTO `user` (`user_id`, `email`, `password`) VALUES
(1, 'email@email.com', '664c0750f8c73ec0086e88c8b02bb112');

 

i still do not understand here :

"' LIMIT 0,1", 41, __FILE__, true );

 

_FILE_ is a php file that need to read (its on another file)

 

but

LIMIT 0,1", 41,

give me headache ..

 

if someone can point me to the right direction

 

thx you very much

Edited by OmeGa3
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.