当前位置: 首页 > 图文教程 > 网络编程 > PHP > php数据库备份参考

PHP
在PHP中以root身份运行外部命令
PHP编程常用技巧四则
实例学习PHP之投票程序篇
PHP中的加密功能
PHP VS ASP
PHP生成动态WAP页面
PHP中for循环语句的几种变型
PHP5.0对象模型探索之对象串行化
PHP5.0对象模型探索之重载
浅议PHP程序开发中的模板选择
用PHP写的身份证验证程序
PHP.MVC的模板标签系统之初识PHP.MVC
PHP程序加速探索之代码优化
PHP程序加速探索之压缩输出gzip
用PHP文件上传的具体思路及实现
使用PHP编写基于Web的文件管理系统
理解PHP中的MVC编程之控制器
PHP程序加速探索之缓存输出
让你的PHP引擎全速运转的三个绝招
PHP程序加速探索之加速工具软件

PHP 中的 php数据库备份参考


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 140 ::
收藏到网摘: n/a

转自:http://www1.blog.163.com/article/-Bov-01EjrIa.html
<?php
 set_time_limit(36000);
  $orders = 9; //目标表序号
  $dbNames = array("seeditbbs","seedblog"); //备份多库
 $con = mysql_connect("localhost","root","h67g4n9s8l"); //h67g4n9s8l
 mysql_select_db("seeditbbs",$con);
  $rs = mysql_query("SHOW GLOBAL VARIABLES"); //读取MYSQL系统变量  while($row = mysql_fetch_row($rs)){     if($row[0]=="datadir"){ 
 $dataDir = $row[1]; //得到MYSQL的DATA目录 
 mysql_free_result($rs); 
 break;} 
 } foreach($dbNames as $dbName){ //循环备份多库     $fromDir = $dataDir;  $toDir = "i:/db_bak/{$dbName}{$orders}/"; //目标目录 if(!is_dir($toDir)) mkdir($toDir ); //建保存目录  $fromDir .= "{$dbName}/"; //源目录  $dirArr = scandir($fromDir);
 foreach($dirArr as $subFile){ //拷备所有表文件 
     if(!@preg_match("|^\.+$|",$subFile)) copy($fromDir.$subFile,$toDir.$subFile); 
  } } ($orders<9) ? $orders++ : $orders=1; //表序号自增,一日9次,备份时间: 1 8 10 12 14 16 18 20 22 $file = file_get_contents($_SERVER["SCRIPT_FILENAME"]);
  $file = preg_replace("|\\\$orders \= \d+|","\$orders = $orders",$file); //修改本文件目标表序号 file_put_contents($_SERVER["SCRIPT_FILENAME"],$file); //保存?>