Php backup database, php backup _ PHP Tutorial

Source: Internet
Author: User
Php backup database and php backup. Php backup database, php backup? Php *** @ namephp backup database * @ paramstring $ DbHost connection host * @ paramstring $ DbUser username * @ paramstring $ DbPwd connection password * php backup database, php backup
 '; $ Link = mysql_connect ($ DbHost, $ DbUser, $ DbPwd) or die ('database connection failed :'. mysql_error (); mysql_select_db ($ DbName) or die ('database connection failed :'. mysql_error (); mysql_query ('set names utf8'); // declare the variable $ isDropInfo = ''; $ insertSQL =''; $ row = array (); $ tables = array (); $ tableStructure = array (); $ fileName = ($ saveFileName? $ SaveFileName: 'MySQL _ data_bakeup _'). date ('ymdhis '). '. SQL '; // enumerate all TABLES in the database $ res = mysql_query ("SHOW TABLES FROM $ DbName"); while ($ row = mysql_fetch_row ($ res )) {$ tables [] = $ row [0];} mysql_free_result ($ res); // enumerate the statement foreach ($ tables as $ val) for creating all tables) {$ res = mysql_query ("show create table $ val", $ link); $ row = mysql_fetch_row ($ res); $ isDropInfo = "drop table if exists '". $ val. "'; \ r \ n"; $ ta BleStructure = $ isDropInfo. $ row [1]. "; \ r \ n"; file_put_contents ($ fileName, $ tableStructure, FILE_APPEND); mysql_free_result ($ res );} // enumerate the INSERT statements of all tables foreach ($ tables as $ val) {$ res = mysql_query ("select * from $ val "); // insert while ($ row = mysql_fetch_row ($ res) {$ sqlStr = "insert '". $ val. "'values ("; foreach ($ row as $ v) {$ sqlStr. = "'$ V'," ;}// remove the last comma $ sqlStr = substr ($ sq LStr, 0, strlen ($ sqlStr)-1); $ sqlStr. = "); \ r \ n"; file_put_contents ($ fileName, $ sqlStr, FILE_APPEND);} mysql_free_result ($ res);} echo 'data backup successful! ';} // Call this method backupMySqlData ('localhost', 'root', '123', 'youdbname');?>

Why? Php/***** @ name php backup database * @ param string $ DbHost connection host * @ param string $ DbUser username * @ param string $ DbPwd connection password *...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.