antonyjohn Posted November 23, 2007 Share Posted November 23, 2007 $db_host = "localhost"; $db_name = "dinasteel"; $db_user = "root"; $db_pass = "zenith2255"; 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"; } $dn_country = datadump ("dn_country"); $dn_payments = datadump ("dn_payments"); $dn_projecttracking = datadump ("dn_projecttracking"); $content = $dn_country . $dn_payments . $dn_projecttracking; $file_name = "MySQL_Database_Backup.sql"; Header("Content-type: application/octet-stream"); Header("Content-Disposition: attachment; filename=$file_name"); echo $content; exit; i have written this program to backup my database....the file is been downloaded....but with some problem when i open the text file ....the written like this.....INSERT INTO dn_country VALUES("","",""); plzzzzzzzz help ...ver is the data Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 23, 2007 Share Posted November 23, 2007 <?php $db_host = "localhost"; $db_name = "dinasteel"; $db_user = "root"; $db_pass = "zenith2255"; 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"; } $dn_country = datadump ("dn_country"); $dn_payments = datadump ("dn_payments"); $dn_projecttracking = datadump ("dn_projecttracking"); $content = $dn_country . $dn_payments . $dn_projecttracking; $file_name = "MySQL_Database_Backup.sql"; Header("Content-type: application/octet-stream"); Header("Content-Disposition: attachment; filename=$file_name"); echo $content; exit; ?> i have written this program to backup my database....the file is been downloaded....but with some problem when i open the text file ....the written like this.....INSERT INTO dn_country VALUES("","",""); plzzzzzzzz help ...ver is the data I'm assuming 'ver' means 'where'... For a start change your query - you have: <?php $query = mysql_query("select * from $table"); ?> Change that to: <?php $sql = "SELECT * FROM $table"; //No where in your code is $table defined! $query = mysql_query($sql) or die(mysql_error); ?> There is (should be) a feature in phpMyAdmin to back up your tables or database (at least on my web-host there is) - you could always just use that. Might be simpler and would probably work. Quote Link to comment Share on other sites More sharing options...
antonyjohn Posted November 23, 2007 Author Share Posted November 23, 2007 there is an option for taking the backup of database in my phpmyadmin..but my client need to do it using the php....so that he can do it with in the website Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 23, 2007 Share Posted November 23, 2007 if I remember correctly those function are there in a function file in phpMyAdmin.. A long time ago I tweak them for a backup system for a site I did, just search the phpMyAdmin directory the functions are pretty easy to change to your needs Quote Link to comment Share on other sites More sharing options...
willpower Posted November 23, 2007 Share Posted November 23, 2007 hi perhaps you could have seen my post on the same subject. I too have the same issue. funny that im using your script dont you think! If i get this sirted i'll let you know Quote Link to comment Share on other sites More sharing options...
willpower Posted November 23, 2007 Share Posted November 23, 2007 Just read my last post...sounded sarcastic...didnt mean to be...sorry Quote Link to comment Share on other sites More sharing options...
willpower Posted November 23, 2007 Share Posted November 23, 2007 right ignore the %table comment because this is part of a function so that section is good 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.