scotch33 Posted December 19, 2006 Share Posted December 19, 2006 Hi there,I am trying to provide a customer with a backup button to my sqldump a database. the code (kindly provided in [url=http://www.devpapers.com/article/55]http://www.devpapers.com/article/55[/url] is...[code]$db_host = "localhost";$db_name = "mydbasename";$db_user = "mydbaseusername";$db_pass = "mydbasepassword";mysql_connect($db_host,$db_user,$db_pass);@mysql_select_db($db_name) or die("Unable to select database.");function datadump ($table) { $result .= "# Dump of $table \n"; $result .= "# Dump DATE : " . date("d-M-Y") ."\n\n"; $query = mysql_query("select * from $table"); $num_fields = @mysql_num_fields($query); $numrow = mysql_num_rows($query); for ($i =0; $i<$numrow; $i++) { $result .= "INSERT INTO ".$table." VALUES("; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) $result .= "\"$row[$j]\"" ; else $result .= "\"\""; if ($j<($num_fields-1)) $result .= ","; } $result .= ");\n"; } return $result . "\n\n\n"; }$dvd_orders = datadump ("dvd_orders");$products = datadump ("products");$content = $dvd_orders . $products;$file_name = "MySQL_Database_Backup.sql";Header("Content-type: application/octet-stream");Header("Content-Disposition: attachment; filename=$file_name");echo $content;exit;[/code]However I am now getting the following results...Warning: Cannot modify header information - headers already sent by (output started at /home/pathto/backup.php:11) in /home/pathto/backup.php on line 42 Warning: Cannot modify header information - headers already sent by (output started at /home/pathto/backup.php:11) in /home/pathto/backup.php on line 43 # Dump of dvd_orders # Dump DATE : 19-Dec-2006 INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); INSERT INTO dvd_orders VALUES("","","","","","","","","","","","","","","","","","","",""); # Dump of products # Dump DATE : 19-Dec-2006 INSERT INTO products VALUES("","","",""); At the moment there is no other code on the php page other than the function - do i need to put some kind of header in to tell the page that it is just executing this script?Thanks!John Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 19, 2006 Share Posted December 19, 2006 a couple of things...1) did you read this?? http://www.phpfreaks.com/forums/index.php/topic,37442.0.html -- it's one of the stickies in this forum and it goes all sorts of into headers. I don't fully understand the massive problems with this item but there is a lot of info; mostly related to passing HTML tags prior to the header commands... 2) Your values in your SQL statements appear to be blank. If that's the case, do some error checking to see why your variables are not acquiring their desired values; this in turn, may lead you to the end problem.3) make sure the username you're using to get into the database has the appropriate rights to perform all of the fucntions your script is wanting it to do. Quote Link to comment Share on other sites More sharing options...
scotch33 Posted December 19, 2006 Author Share Posted December 19, 2006 Hi there,Thanks! that was a useful article - however, I have done a little with headers before and the first thing I did check was if there was anything there. There is nothing at all in the page before the <?php start, not even white space.Your second point - I am not sure where to even start with error checking on this so iof anyone can give me a pointer or point me at articales related I would appreciate it.the database has only one usename and password, which are the ones I am using to get to the database. they are also used on all the other pages in the site accessing the database and there is no problem with them.Any further help would be appreciated.Thanks again. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 19, 2006 Share Posted December 19, 2006 I just copied your code and attempted to use it against my DBs... your loops are not pulling the ifnormation you're expecting it to. you need to start there before moving onto the Header issue. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 19, 2006 Share Posted December 19, 2006 you need to loop thorugh your $query variable to get the values. Right now you're just doing the query and counting the results and counting the fields, you're not pulling any of the information. Quote Link to comment Share on other sites More sharing options...
Orio Posted December 19, 2006 Share Posted December 19, 2006 You might wanna look into this ;)http://www.phpfreaks.com/script/view/11.phpOrio. Quote Link to comment Share on other sites More sharing options...
scotch33 Posted December 20, 2006 Author Share Posted December 20, 2006 Thanks Orio.This looks ideal. One question - whilkst reading the instructions it mentions[quote]If running from shell, put this above the <?php "#! /usr/bin/php -q" without the quotes!!![/quote]It further mentions that if I am going to cron this and keep the database safe,. then this is teh best option. Am i right in assuming the running from shell, is running from the root folder rather than the public_html folder?Thanks!John. Quote Link to comment 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.