Table of Contents
Share a php class library to implement MYSQL backup, phpmysql backup class library
Home Backend Development PHP Tutorial Share a php class library that implements MYSQL backup, phpmysql backup class library_PHP tutorial

Share a php class library that implements MYSQL backup, phpmysql backup class library_PHP tutorial

Jul 13, 2016 am 10:14 AM
mysql

Share a php class library to implement MYSQL backup, phpmysql backup class library

I just want to study how to back up the database, share a php class library to implement MYSQL backup

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

<?php

/******   备份数据库结构 ******/

/****正好要研究如何备份数据库,分享一个php实现MYSQL备份的类库********/

      /*

      函数名称:table2sql()

      函数功能:把表的结构转换成为SQL

      函数参数:$table: 要进行提取的表名

      返 回 值:返回提取后的结果,SQL集合

      函数作者:heiyeluren

      */

    

     function table2sql($table)

      {

          global $db;

         $tabledump = "DROP TABLE IF EXISTS $table;\n";

         $createtable = $db->query("SHOW CREATE TABLE $table");

         $create = $db->fetch_row($createtable);

         $tabledump .= $create[1].";\n\n";

          return $tabledump;

      }

    

    

     /****** 备份数据库结构和所有数据 ******/

      /*

      函数名称:data2sql()

      函数功能:把表的结构和数据转换成为SQL

      函数参数:$table: 要进行提取的表名

      返 回 值:返回提取后的结果,SQL集合

      函数作者:heiyeluren

      */

     function data2sql($table)

      {

          global $db;

         $tabledump = "DROP TABLE IF EXISTS $table;\n";

         $createtable = $db->query("SHOW CREATE TABLE $table");

         $create = $db->fetch_row($createtable);

         $tabledump .= $create[1].";\n\n";

    

         $rows = $db->query("SELECT * FROM $table");

         $numfields = $db->num_fields($rows);

         $numrows = $db->num_rows($rows);

          while ($row = $db->fetch_row($rows))

          {

             $comma = "";

             $tabledump .= "INSERT INTO $table VALUES(";

              for($i = 0; $i < $numfields; $i++)

              {

                 $tabledump .= $comma."'".mysql_escape_string($row[$i])."'";

                 $comma = ",";

              }

             $tabledump .= ");\n";

          }

         $tabledump .= "\n";

    

          return $tabledump;

      }

?>

Copy after login

Detailed description: http://php.662p.com/thread-560-1-1.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/910349.htmlTechArticleShare a php class library to implement MYSQL backup. The phpmysql backup class library is just for studying how to back up the database. Share a php Class library to implement MYSQL backup?php/****** Backup database structure...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

How to use MySQL backup and restore in PHP?

What are the application scenarios of Java enumeration types in databases? What are the application scenarios of Java enumeration types in databases? May 05, 2024 am 09:06 AM

What are the application scenarios of Java enumeration types in databases?

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into a MySQL table using PHP?

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

How to use MySQL stored procedures in PHP?

Performance optimization strategies for PHP array paging Performance optimization strategies for PHP array paging May 02, 2024 am 09:27 AM

Performance optimization strategies for PHP array paging

See all articles