php 備份數(shù)據(jù)庫類
<?php/****** 備份數(shù)據(jù)庫結(jié)構(gòu) ******//****正好要研究如何備份數(shù)據(jù)庫,分享一個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. chat.asp聊天程序的編寫方法2. jsp EL表達(dá)式詳解3. asp知識整理筆記4(問答模式)4. IntelliJ IDEA 統(tǒng)一設(shè)置編碼為utf-8編碼的實(shí)現(xiàn)5. 解決ajax的delete、put方法接收不到參數(shù)的問題方法6. Django ORM實(shí)現(xiàn)按天獲取數(shù)據(jù)去重求和例子7. idea修改背景顏色樣式的方法8. XML入門的常見問題(一)9. Jsp中request的3個基礎(chǔ)實(shí)踐10. 怎樣才能用js生成xmldom對象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?
