php 備份數(shù)據(jù)庫類
<?php/****** 備份數(shù)據(jù)庫結構 ******//****正好要研究如何備份數(shù)據(jù)庫,分享一個php實現(xiàn)MYSQL備份的類庫********/ /* 函數(shù)名稱:table2sql() 函數(shù)功能:把表的結構轉換成為SQL 函數(shù)參數(shù):$table: 要進行提取的表名 返 回 值:返回提取后的結果,SQL集合 函數(shù)作者: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].';nn'; return $tabledump; } /****** 備份數(shù)據(jù)庫結構和所有數(shù)據(jù) ******/ /* 函數(shù)名稱:data2sql() 函數(shù)功能:把表的結構和數(shù)據(jù)轉換成為SQL 函數(shù)參數(shù):$table: 要進行提取的表名 返 回 值:返回提取后的結果,SQL集合 函數(shù)作者: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].';nn'; $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; }?>
相關文章:
1. ThinkPHP6使用JWT+中間件實現(xiàn)Token驗證實例詳解2. log4net在Asp.net MVC4中的使用過程3. ASP基礎入門第二篇(ASP基礎知識)4. ASP.NET MVC實現(xiàn)登錄后跳轉到原界面5. Python如何解決secure_filename對中文不支持問題6. JSP出現(xiàn)中文亂碼問題解決方法詳解7. ASP.NET MVC限制同一個IP地址單位時間間隔內的請求次數(shù)8. 不使用XMLHttpRequest對象實現(xiàn)Ajax效果的方法小結9. TP5使用RabbitMQ實現(xiàn)消息隊列的項目實踐10. 怎樣打開XML文件?xml文件如何打開?
