在公司(网络)的服务器上有很多网站,我上传网站时对其他瓦干也有同样的权限。所以就想把同事的网站荡下来学习一下。有了源代码,没有数据库什么也运行不了啊。服务器的数据库是安网站开的,每一个网站把*.sql发给服务器管理员,由管理员导入到数据库中。但是数据库账号密码不能登陆只能执行sql语句。所以我就想起来做一个简易的,类似于phpmyadmin的数据库导出功能。这样我就可以轻松的获得所有网站的数据库了。
用这个程序可以实现简单的数据导出(生成的脚本可直接在phpmyadmin执行)。进一步的功能还可以慢慢扩展。当然不要用来盗用别人机密的冬冬了。
其中解析的数据类型还不全,只是集中简单的常用类型。如果那位仁兄,发现了其他不适用的类型,请告诉我mailto:woaini4651@yahoo.com.cn。
index.php
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>数据库备份</title> <style type="text/css"> .borderoff{ border-style:none; background-color:#F3F3F3} </style> </head> <body> <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center"> <tr valign="top"> <td height="378"><br> <form action="cmd.php" method="post" name="backup" target="_blank" id="backup"> <table width="500" border="0" cellspacing="1" cellpadding="4" align="center"> <tr> <td colspan="2" align="center">数据库备份</td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right"> 服务器名:</td> <td width="313"><input name="hostname" type="text" class="borderoff" value="localhost" size="35" maxlength="50"> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right"> 数据库名:</td> <td width="313"><input name="database" type="text" class="borderoff" value="yes_da" size="35" maxlength="50"> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right">账 号:</td> <td width="313"><input name="username" type="text" class="borderoff" value="root" size="35" maxlength="50"> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right">密 码:</td> <td width="313"><input name="password" type="text" class="borderoff" size="35" maxlength="50"> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right"> 完全备份:</td> <td width="313"> <input type="radio" name="backup_type" value="full" checked> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right">只备份结构:</td> <td width="313"> <input type="radio" name="backup_type" value="structure"> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right">只备份数据:</td> <td width="313"> <input type="radio" name="backup_type" value="data"> </td> </tr> <tr bgcolor="#F3F3F3"> <td width="166" align="right">采用压缩格式:</td> <td width="313"> <input type="radio" name="gzipcompress" value="0" checked> 否 <input type="radio" name="gzipcompress" value="1"> 是(zip)</td> </tr> <tr> <td colspan="2" align="center"> <input name="backupstart" type="submit" value="开始备份"> </td> </tr> </table> </form> <p align="center"> <br> <br> </p></td> </tr> </table> </body> </html>
cmd.php
<?php if(isset($_POST[''''backupstart''''])) { $hostname = trim($_POST[''''hostname'''']); $database = trim($_POST[''''database'''']); $username = trim($_POST[''''username'''']); $password = trim($_POST[''''password'''']); $backtype = $_POST[''''backup_type'''']; $gz = $_POST[''''gzipcompress'''']; $link = @mysql_pconnect($hostname, $username, $password); if(!$link) { //连接数据库 echo "数据库打开出错!"; exit(); }//end if $table_list = get_table_list($link,$database); if($table_name===false) { //检索数据库的表 echo "数据库打开出错!!"; exit(); }//end if //echo "<pre>"; //print_r($table_list); $table_code = ""; while(list($key,$table_name)=each($table_list)) { //执行对每一个表的数据返回 if($backtype!="data") { //备份结构 $table_code .= get_table_code($link,$database,$table_name); }//end if if($backtype!="structure") { //备份数据 $table_code .= get_table_data($link,$database,$table_name); }//end if }//end while //echo $table_code; if($gz==0) { //输出 $filename = $database.".sql"; $handle = fopen($filename, "a+"); $temp = fwrite($handle, $table_code); echo $temp; fclose($handle); //header("location:",$filename); echo "<script>location.replace(''''".$file [1] [2] 下一页 没有相关教程
|