On 20 Jul 2004 06:45:20 -0700
bi******@yahoo.co.uk (mr_burns) wrote:
hi,
i have recently used a system (oscommerce store) where you can backup
your database. what happens is that when you click 'backup database',
it creates an SQL string, stores it in a text file and lets you
download it to your hard drive.
is there a simple means of creating this SQL file? if not, are there
any free scripts available that can be used on any database/table and
create a SQL string to be stored in a text file?
also, how do you (once the SQL file has been created) then prompt the
user to save the file onto their computer? cheers
Simple.
If you're on a *nix system, you can use the shell-command "mysqldump"
for dumping the content and forcing a download of the file is just a
simple http-header.
Example: Dump database "test" and offer download.
<?php
// username and password for the database
$db_user = "someuser";
$db_pass = "somepass";
$db = "test";
// Filename to suggest to the user.
$filename = "db_backup.sql";
// shell command
$cmd = "mysqldump -u $db_user -p $db_pass $db";
// send headers, forcing download:
header("Content-type: text/html");
header("Content-Disposition: attachment; filename=\"$filename\"");
// Run $cmd and pass the output directly to the browser.
passthru($cmd);
?>
Now you can just modify this to suit your needs (set the vars
dynamically perhaps) and point users to that for backing up their db.
If you're not on a *nix box I'm not sure how it's done, sorry. :(
Madsen
--
Anders K. Madsen ---
http://lillesvin.linux.dk
"There are 10 types of people in the world.
Those who understand binary - and those who don't."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA/SfdlNHJe/JASHcRAnIKAJ93bEAUl1INTgl+QQsmz5OSKUfw3QCaA0ty
qyxf+1yhgSLX1iMFNkuCcfI=
=2x3b
-----END PGP SIGNATURE-----