spacepoet Posted April 29, 2011 Share Posted April 29, 2011 Hello: I have a question and I think this is where to ask it. I want to add a feature in my admin panel that is a link that - when click - will export all the data from a mySQL database as a .TXT or .SQL (preferred) and open it in a "Save As" prompt box so the admin can save a copy to his or her computer. Basically, I want the admin to download a copy of the database each time they make an update so he or she has a current copy of the database stored as a backup on his or her local machine. Can this be done? If so, how? My GOOGLE searches have not produced any results for this. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/ Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 SELECT ... INTO OUTFILE 'file_name' Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208278 Share on other sites More sharing options...
spacepoet Posted April 30, 2011 Author Share Posted April 30, 2011 Hi: Thanks for the reply, but I'm not sure what you mean. Something like: Export.php <?php SELECT myDataBase INTO OUTFILE 'file_name' ?> Admin.php <a href="Export.php">Export Database</a> ?? Sorry, a little confused .. Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208742 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 yes so you might have $table_dump = mysql_query("select table_name INTO OUTFILE '/example/path/file.txt'") or die("unable to move data"); Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208755 Share on other sites More sharing options...
spacepoet Posted April 30, 2011 Author Share Posted April 30, 2011 OK, I see what you mean .. but what if I want to do all the tables, not just one. Meaning, I want to export the whole database as one file. Also, is there a trick to add the date and time to each file, so it can be easy to find by date and time. Thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208758 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 to dump all of your tables into a file you would write $table_dump = mysql_query("select * INTO OUTFILE '/example/path/file.txt'") or die("unable to move data"); change the table_name to *...teling it to select all of the tables instead of specified ones..hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208762 Share on other sites More sharing options...
spacepoet Posted April 30, 2011 Author Share Posted April 30, 2011 Hi: Maybe I am not understanding it properly .. Do I need to do soemthing like this: <?php include('../include/myConn.php'); $table_dump = mysql_query("SELECT * INTO OUTFILE 'DataBaseBackUp.txt'") or die("unable to move data"); while($result=mysql_fetch_array($query)) echo ". $result()."; ?> Just using the one line produced "unable to move data" .. As does the above code ... Do I somehow need to write it out into the file? Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208789 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 Does it work when you love a specified table? Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208798 Share on other sites More sharing options...
spacepoet Posted April 30, 2011 Author Share Posted April 30, 2011 Hi: No, I tried it that was as well .. Don't know what to do .. Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208808 Share on other sites More sharing options...
fugix Posted May 1, 2011 Share Posted May 1, 2011 well to put you in the right direction so that you can figure this out...I will gibe you a link here Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1208946 Share on other sites More sharing options...
fugix Posted May 1, 2011 Share Posted May 1, 2011 sorry about above here is the link Quote Link to comment https://forums.phpfreaks.com/topic/235105-exporting-mysql-data-as-a-txt-or-sql-file-for-backup/#findComment-1209046 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.