MuSQL imports and exports the entire database as a file
MuSQL imports and exports the entire database as a file:
<? Php/* export SELECT * into outfile 'C:/name.txt 'fields TERMINATED by', 'optionally ENCLOSED by' \ 'Lines terminated by '\ n' FROM zones; import load data infile 'C:/name.txt 'into TABLE zones fields terminated by', 'optionally ENCLOSED by' \ 'Lines terminated by '\ n'; */define (HOST, '2017. 0.0.1 '); define (USER, 'user'); define (PWD, 'pwd'); define (DBNAME, 'dbname'); define (DIR, 'c: /xampp/htdocs/backup/'); // 1: Import 0: Export define (OPERATION, 1); mysql_connect (HOST, USER, PWD) ordie ("cocould not connect :". mysql_error (); mysql_select_db (DBNAME) ordie ("cocould not select db :". mysql_error (); $ result = mysql_query ("show tables"); if (! Is_dir (DIR) {die ('Folder does not exist');} if (OPERATION) {while ($ row = mysql_fetch_array ($ result, MYSQL_NUM )) {$ fileName = DIR. $ row [0]. ". txt "; if (file_exists ($ fileName) {$ querySql = 'truncate Table ''. $ row [0]. '''; mysql_query ($ querySql) ordie ("cocould not truncate table :". $ querySql. mysql_error (); $ querySql = "load data infile '". $ fileName. "'into table '". $ row [0]. "'fields TERMINATED by', 'optionally E Nclosed by '\ ''lines terminated by' \ N' "; mysql_query ($ querySql) ordie (" cocould not insert into table :". $ querySql. mysql_error (); echo 'insert into Table '. $ row [0]. 'success. <br/> ';} else {echo 'not insert into Table '. $ row [0]. '<br/>';} echo "The task is finished";} else {if (is_writable (DIR) {while ($ row = mysql_fetch_array ($ result, MYSQL_NUM) {$ fileName = DIR. $ row [0]. ". txt "; if (file_exists ($ fileName)) {Unlink ($ fileName);} $ querySql = "SELECT * into outfile '". $ fileName. "'fields TERMINATED by', 'optionally enclosed by '\ ''lines terminated by' \ n' FROM '". $ row [0]. "'"; mysql_query ($ querySql) ordie ("cocould not dump table :". $ querySql. mysql_error (); echo 'dump Table '. $ row [0]. 'success. <br/> ';} echo "The task is finished";} else {echo 'folder '. DIR. 'Can not writeable';} mysql_free_result ($ result); m Ysql_close ();?>