php 備份數(shù)據(jù)庫類
<?php/****** 備份數(shù)據(jù)庫結(jié)構(gòu) ******//****正好要研究如何備份數(shù)據(jù)庫,分享一個(gè)php實(shí)現(xiàn)MYSQL備份的類庫********/ /* 函數(shù)名稱:table2sql() 函數(shù)功能:把表的結(jié)構(gòu)轉(zhuǎn)換成為SQL 函數(shù)參數(shù):$table: 要進(jìn)行提取的表名 返 回 值:返回提取后的結(jié)果,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ù)庫結(jié)構(gòu)和所有數(shù)據(jù) ******/ /* 函數(shù)名稱:data2sql() 函數(shù)功能:把表的結(jié)構(gòu)和數(shù)據(jù)轉(zhuǎn)換成為SQL 函數(shù)參數(shù):$table: 要進(jìn)行提取的表名 返 回 值:返回提取后的結(jié)果,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; }?>
相關(guān)文章:
1. 完美解決vue 中多個(gè)echarts圖表自適應(yīng)的問題2. SpringBoot+TestNG單元測(cè)試的實(shí)現(xiàn)3. vue實(shí)現(xiàn)web在線聊天功能4. idea配置jdk的操作方法5. VMware中如何安裝Ubuntu6. Springboot 全局日期格式化處理的實(shí)現(xiàn)7. python 浮點(diǎn)數(shù)四舍五入需要注意的地方8. Docker容器如何更新打包并上傳到阿里云9. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法10. JAMon(Java Application Monitor)備忘記
