The PHP backup database is an SQL file and the source code can be downloaded.

Source: Internet
Author: User

This is an SQL file that backs up all tables in a specified database and can be downloaded. This source code comes from the dedecms program. It has many functions and is very practical, but the quality of the Code remains to be improved.

 
 
  1. <!? Php
  2. /****** Back up the database structure ******/
  3. /*
  4. Function Name: table2sql ()
  5. Function: converts the table structure to SQL
  6. Function parameter: $ table: name of the table to be extracted
  7. Return Value: return the extracted results, SQL set
  8. Function Author: heiyeluren
  9. */
  10. Function table2sql ($ table)
  11. {
  12. Global $ db;
  13. $ Tabledump = "drop table if exists $ table ;";
  14. $ Createtable = $ db ---> query ("show create table $ table ");
  15. $ Create = $ db-> fetch_row ($ createtable );
  16. $ Tabledump. = $ create [1]. ";";
  17. Return $ tabledump;
  18. }
  19. /****** Back up the database structure and all data ******/
  20. /*
  21. Function Name: data2sql ()
  22. Function: converts the table structure and data into SQL statements.
  23. Function parameter: $ table: name of the table to be extracted
  24. Return Value: return the extracted results, SQL set
  25. Function Author: heiyeluren
  26. */
  27. Function data2sql ($ table)
  28. {
  29. Global $ db;
  30. $ Tabledump = "drop table if exists $ table ;";
  31. $ Createtable = $ db-> query ("show create table $ table ");
  32. $ Create = $ db-> fetch_row ($ createtable );
  33. $ Tabledump. = $ create [1]. ";";
  34. $ Rows = $ db-> query ("SELECT * FROM $ table ");
  35. $ Numfields = $ db-> num_fields ($ rows );
  36. $ Numrows = $ db-> num_rows ($ rows );
  37. While ($ row = $ db-> fetch_row ($ rows ))
  38. {
  39. $ Comma = "";
  40. $ Tabledump. = "insert into $ table VALUES (";

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.