Tag:io ar os sp for file on data bs
<?phpheader ("Content-type:text/html;charset=utf-8"); $database = "Thinksns_3_1"; $link = mysql_connect (' LocalHost ', ' root ', ' 123456 ') or Die (' Connection failed '), mysql_select_db ($database) or Die (' connection database failed ');//Select Encoding mysql_query ("set Names UTF8 ")//1. Get all Tables $rs = mysql_query (" SHOW TABLES from $database "), $tableArray = Array (); while ($row = Mysql_fetch_ro W ($rs)) {$tableArray [] = $row [0];} Mysql_free_result ($rs);//2. Profile Name $to_file_name = "./". Time (). SQL "; $info ="/* ". Date (' y-m-d ')." Export Data */\r\n "; File_put_contents ($to _file_name, $info, file_append);//3. Loop table foreach ($tableArray as $val) {$sql =" show CREATE TABLE ". $val; $res = mysql_query ($sql, $link); $row = Mysql_fetch_array ($res); $info ="/*--table structure for ". $va L. " ' */\r\n '; $info. = "DROP TABLE IF EXISTS '". $val. " '; \ r \ n '; $sqlStr = $info. $row [1]. "; r\n\r\n ";//Append to File File_put_contents ($to _file_name, $SQLSTR, file_append);//Release Resources mysql_free_result ($res); $sql =" SELECT * from ". $val; $res = mysql_query ($sql, $link);//If there is no data in the table, continue to the next table if (Mysql_num_rows ($res) <1) continue;//$info = "/*--Records for". $val. " ' */\r\n '; file_put_contents ($to _file_name, $info, file_append);//Read data while ($row = Mysql_fetch_row ($res)) {$sqlStr = " INSERT into ' ". $val." ' VALUES ("; foreach ($row as $zd) {$sqlStr. =" ' ". $zd." ', ";} Remove the last comma and space $sqlstr = substr ($sqlStr, 0,strlen ($SQLSTR)-2); $sqlStr. = "); \ r \ n"; file_put_contents ($to _file_name,$ Sqlstr,file_append);} Release Resources mysql_free_result ($res); File_put_contents ($to _file_name, "\ r \ n", file_append);} Header ("Content-type:application/octet-stream"), Header ("Accept-ranges:bytes"), Header ("Accept-length:". FileSize ($to _file_name)); Header ("content-disposition:attachment; Filename= ". $to _file_name); ReadFile ($to _file_name); echo "Data all Around";
Program BACKUP Database