php 備份數(shù)據(jù)庫(kù)類
<?php/****** 備份數(shù)據(jù)庫(kù)結(jié)構(gòu) ******//****正好要研究如何備份數(shù)據(jù)庫(kù),分享一個(gè)php實(shí)現(xiàn)MYSQL備份的類庫(kù)********/ /* 函數(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ù)庫(kù)結(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. PHP里10個(gè)鮮為人知但卻非常有用的函數(shù)2. Docker 通過(guò)端口來(lái)連接一個(gè)容器的實(shí)現(xiàn)3. css進(jìn)階學(xué)習(xí) 選擇符4. vue實(shí)現(xiàn)分頁(yè)的三種效果5. Django之choices選項(xiàng)和富文本編輯器的使用詳解6. Python搭建Keras CNN模型破解網(wǎng)站驗(yàn)證碼的實(shí)現(xiàn)7. 用python登錄帶弱圖片驗(yàn)證碼的網(wǎng)站8. 利用jupyter網(wǎng)頁(yè)版本進(jìn)行python函數(shù)查詢方式9. Eclipse集成 Lomboz和JBoss開(kāi)發(fā)J2EE10. 解決python腳本中error: unrecognized arguments: True錯(cuò)誤
