PHP Database backup Script
PHP Database backup Script
The code is as follows:
Backing Up the database
$host = "localhost";
$user = "root"; Database account
$password = ""; Database Password
$dbname = "MySQL"; Database name
The account number, password, and name are all transmitted from the page.
if (!mysql_connect ($host, $user, $password))//Connect MySQL Database
{
Echo ' Database connection failed, please check and try again ';
Exit
}
if (!mysql_select_db ($dbname))//whether the database exists
{
Echo ' does not exist database: '. $dbname. ', please check and try again ';
Exit
}
mysql_query ("Set names ' UTF8 '");
$mysql = "Set charset UTF8;";
$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 ']. "; ";
$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);";
}
}
$filename = $dbname. Date (' Ymjgi '). ". SQL"; Storage path, default to the outermost layer of the project
$fp = fopen ($filename, ' w ');
Fputs ($fp, $mysql);
Fclose ($FP);
echo "Data backup succeeded";
?>
http://www.bkjia.com/PHPjc/1049989.html www.bkjia.com true http://www.bkjia.com/PHPjc/1049989.html techarticle PHP database backup script PHP database backup script code is as follows:? PHP//backup database $host = localhost; $user = root;//Database account $password =;//Database Password $dbname ...