phpmyadmin可以简单的来实现备份和恢复。至于用程序来做也差不多,你看看phpmyadmin的代码就知道了,很简单的。
解决方案 »
- 关于PHP5.3作废函数的处理方法
- sitemap上传google错误,图显示问题,网址是http://meiaimei.host22.com/sitemap.xml
- 有谁知道如何给论坛上的用户自动发送短消息。
- PHP 怎么做成象网上银行一样的数字证书啊
- (菜鸟飞飞) 页面内点击按钮,出现当前系统的时间戳
- 关于php url重写
- [PHP]php读取通过url得到的json文本中集合为空(在线等,谢谢)
- 如何利用接口中读到的参数查询本地数据库?
- 怎么样能让javascrit代码调用php代码?
- 求大神帮写一个正则
- 还是那个搜索的问题,大家帮我看看 基本上已经做好了,但是在给搜索结果加分页显示的时候出的问题
- if(empty(strpos($fileele["dirname"],"\\images\\"))) 為什麼會出錯???
里面的中文都是方框呢???!
里面的中文都是方框呢???!"
你的语言设置不正确。
应该没有啊!?
//备份数据
$i = 0;
$crlf="\r\n";
$dbname="xgtqr";
global $dbconn;
$dbconn = mysql_connect("localhost","root","root");
$db = mysql_select_db("xgtqr",$dbconn);
$tables = mysql_list_tables("xgtqr",$dbconn);
$num_tables = @mysql_numrows($tables);
while($i < $num_tables)
{
$table = mysql_tablename($tables, $i); print $crlf;
print $crlf; echo get_table_def($dbname, $table, $crlf).";$crlf$crlf";
echo get_table_content($dbname, $table, $crlf);
$i++;
}//定义抽取表结构与数据
function get_table_def($db, $table, $crlf)
{
global $drop; $schema_create = "";
if(!empty($drop))
$schema_create .= "DROP TABLE IF EXISTS $table;$crlf"; $schema_create .= "CREATE TABLE $table ($crlf";
$result = mysql_db_query($db, "SHOW FIELDS FROM $table");
while($row = mysql_fetch_array($result))
{
$schema_create .= " $row[Field] $row[Type]"; if(isset($row["Default"]) && (!empty($row["Default"]) || $row["Default"] == "0"))
$schema_create .= " DEFAULT '$row[Default]'";
if($row["Null"] != "YES")
$schema_create .= " NOT NULL";
if($row["Extra"] != "")
$schema_create .= " $row[Extra]";
$schema_create .= ",$crlf";
}
$schema_create = ereg_replace(",".$crlf."$", "", $schema_create);
$result = mysql_db_query($db, "SHOW KEYS FROM $table");
while($row = mysql_fetch_array($result))
{
$kname=$row['Key_name'];
if(($kname != "PRIMARY") && ($row['Non_unique'] == 0))
$kname="UNIQUE|$kname";
if(!isset($index[$kname]))
$index[$kname] = array();
$index[$kname][] = $row['Column_name'];
} while(list($x, $columns) = @each($index))
{
$schema_create .= ",$crlf";
if($x == "PRIMARY")
$schema_create .= " PRIMARY KEY (" . implode($columns, ", ") . ")";
elseif (substr($x,0,6) == "UNIQUE")
$schema_create .= " UNIQUE ".substr($x,7)." (" . implode($columns, ", ") . ")";
else
$schema_create .= " KEY $x (" . implode($columns, ", ") . ")";
} $schema_create .= "$crlf)";
return (stripslashes($schema_create));
}//保存数据表的值
function get_table_content($db, $table, $crlf)
{
$schema_create = "";
$temp = "";
$result = mysql_db_query($db, "SELECT * FROM $table");
$i = 0;
while($row = mysql_fetch_row($result))
{
$schema_insert = "INSERT INTO $table VALUES (";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= " NULL,";
elseif($row[$j] != "")
$schema_insert .= " '".addslashes($row[$j])."',";
else
$schema_insert .= " '',";
}
$schema_insert = ereg_replace(",$", "", $schema_insert);
$schema_insert .= ");$crlf";
$temp = $temp.$schema_insert ;
$i++;
}
return $temp;
}
?>