edwardcox Posted December 12, 2008 Share Posted December 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/ Share on other sites More sharing options...
corbin Posted December 12, 2008 Share Posted December 12, 2008 You'll probably either have to code a tool your self or do it manually. Because of the different field types, it would be super hard to code something though. Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-713396 Share on other sites More sharing options...
Maq Posted December 12, 2008 Share Posted December 12, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-713405 Share on other sites More sharing options...
fenway Posted December 12, 2008 Share Posted December 12, 2008 Why not just write a custom mysql_query() functions that simply dumps out the query text to a file? Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-713707 Share on other sites More sharing options...
OmeGa3 Posted January 6, 2013 Share Posted January 6, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-1403682 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2013 Share Posted January 6, 2013 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) Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-1403701 Share on other sites More sharing options...
OmeGa3 Posted January 6, 2013 Share Posted January 6, 2013 Cheers PFMaBiSmAd , the mysl_fetch_field is very interressing .... http://php.net/manual/en/mysqli-result.fetch-fields.php thx you Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-1403705 Share on other sites More sharing options...
OmeGa3 Posted January 6, 2013 Share Posted January 6, 2013 (edited) 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 January 6, 2013 by OmeGa3 Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-1403726 Share on other sites More sharing options...
Christian F. Posted January 6, 2013 Share Posted January 6, 2013 The query itself ends after "LIMIT 0,1", so the comma and everything after it are parameters to the custom method query (). I suspect they're there for debugging/error logging purposes. As for what LIMIT does, a quick Google search can answer that one. Quote Link to comment https://forums.phpfreaks.com/topic/136631-reverse-engineer-a-mysql-databasetable-from-php-source-files/#findComment-1403744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.