PHP backup MySQL Database source code, when applied, please remove the front line number.
- $host = "localhost";
- $user = "root";
- $password = "";
- $dbname = "";
- Mysql_connect ($host, $user, $password);
- mysql_select_db ($dbname);
- $mysql = "Set CharSet Utf8;rn";
- $q 1=mysql_query ("Show Tables");
- while ($t =mysql_fetch_array ($q 1)) {
- $table = $t [0];
- $q 2=mysql_query ("Show create Table ' $table '");
- $sql =mysql_fetch_array ($q 2);
- $mysql. = $sql [' Create Table ']. " Rnrn ";
- $q 3=mysql_query ("select * from ' $table");
- while ($data =mysql_fetch_assoc ($q 3)) {
- $keys =array_keys ($data);
- $keys =array_map (' addslashes ', $keys);
- $keys =join (', ', $keys);
- $keys = "'. $keys." `";
- $vals =array_values ($data);
- $vals =array_map (' addslashes ', $vals);
- $vals =join ("', '", $vals);
- $vals = "'" $vals. "'";
- $mysql. = "INSERT INTO ' $table ' ($keys) values ($vals); RN";
- }
- $mysql. = "RN";
- }
- $filename =date (' YMJ '). SQL ";
- $fp = fopen ($filename, ' w ');
- Fputs ($fp, $mysql);
- Fclose ($FP);
- echo "Data backup succeeded, generate backup file". $filename. "";