PHP backup database for SQL file and downloadable source _php tutorial

Source: Internet
Author: User
Tags vars
This is a backup of all the tables in the specified database to a SQL file that can be downloaded. The source code from the DEDECMS program, a lot of functions, but also very practical, but the quality of the codes need to be improved

 
 
  1. /****** backing up the database structure ******/
  2. /*
  3. function Name: Table2sql ()
  4. function function: Convert the structure of a table into SQL
  5. function Parameters: $table: The name of the table to extract
  6. return value: Returns the extracted result, SQL collection
  7. function Author: heiyeluren
  8. */
  9. function table2sql ($table)
  10. {
  11. Global $db;
  12. $tabledump = "DROP TABLE IF EXISTS $table;" ;
  13. $createtable = $db --->query ("SHOW CREATE TABLE $table");
  14. $create = $db ->fetch_row ($createtable);
  15. $tabledump .= $create [1]. ";" ;
  16. return $tabledump;
  17. }
  18. /****** backing up the database structure and all data ******/
  19. /*
  20. function Name: Data2sql ()
  21. function function: Convert the structure and data of a table into SQL
  22. function Parameters: $table: The name of the table to extract
  23. return value: Returns the extracted result, SQL collection
  24. function Author: heiyeluren
  25. */
  26. function data2sql ($table)
  27. {
  28. Global $db;
  29. $tabledump = "DROP TABLE IF EXISTS $table;" ;
  30. $createtable = $db ->query ("SHOW CREATE TABLE $table");
  31. $create = $db ->fetch_row ($createtable);
  32. $tabledump .= $create [1]. ";" ;
  33. $rows = $db ->query ("select * from $table");
  34. $numfields = $db ->num_fields ($rows);
  35. $numrows = $db ->num_rows ($rows);
  36. while ($row = $db->fetch_row ($rows))
  37. {
  38. $comma = "" ;
  39. $tabledump .= INSERT into $table VALUES (";
  40. http://www.bkjia.com/PHPjc/486044.html www.bkjia.com true http://www.bkjia.com/PHPjc/486044.html techarticle This is a backup of all the tables in the specified database to a SQL file that can be downloaded. The source code from the DEDECMS program, a lot of functions, but also very practical, but the quality of the codes have yet to be improved ...

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.