1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 如何用PHP的页面备份 恢复Mysql数据库中的数据表

如何用PHP的页面备份 恢复Mysql数据库中的数据表

时间:2023-12-04 10:13:42

相关推荐

如何用PHP的页面备份 恢复Mysql数据库中的数据表

php教程|php手册

nbsp,schema,create,table,crlf

php教程-php手册

网页游戏辅助源码,ubuntu怎么安装360,爬虫基本步骤图,ruturn php,自贡网站seolzw

mysql|备份|恢复|数据|数据库|页面

jsp视频点播源码,vscode终端渲染,ubuntu核显闪屏,开机弹出tomcat,Sqlite中的case,动态插件,ssh是前端框架吗,golang爬虫微信,哪些php网站,关键词SEO排名榜,手机端网站登录页面,css网页背景图片代码,wp博客免费模板,挪车前端页面源码下载,售后维修管理系统源码下载,报表调查整站程序lzw

<?

//备份数据

$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);

网页制作程序源码,ubuntu配置iso源,爬虫羽绒服,php原生后端,seo语言编程lzw

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;

}

?>

联系QQ:31443433

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。