/ Published in: PHP
Database backup function that you can call whenever you want — including nightly CRONs.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php backup_tables('localhost','misslily','misslily','blog','*'); /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*'){ $return = ""; //get all of the tables if($tables == '*') { { $tables[] = $row[0]; } } else { } //cycle through foreach($tables as $table) { $return.= 'DROP TABLE '.$table.';'; $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file } ?>
URL: http://davidwalsh.name/backup-mysql-database-php