?
			
	
						
						
						
						
						
						
						
																		
    
        
    
        
                        
                
                    
                
                
                
                    
                
                
                
                    
                
                
                
                    
                
                        
    
 																		
						
																		
    
        
 												
						
																		
	
	
		
				
			
																		
						
						
					
				
				                | 
								1
 
								2
 
								3
 
								4
 
								5
 
								6
 
								7
 
								8
 
								9
 
								10
 
								11
 
								12
 
								13
 
								14
 
								15
 
								16
 
								17
 
								18
 
								19
 
								20
 
								21
 
								22
 
								23
 
								24
 
								25
 
								26
 
								27
 
								28
 
								29
 
								30
 
								31
 
								32
 
								33
 
								34
 
								35
 
								36
 
								37
 
								38
 
								39
 
								40
 
								41
 
								42
 
								43
 
								44
 
								45
 
								46
 
								47
 
								48
 
								49
 
								50
 
								51
 
								52
 
								53
 
								54
 
								55
 
								56
 
								57
 
								58
 
								59
 
								60
 
								61
 
								62
 
								63
 
								64
 
								65
 
								66
 
								67
 
								68
 
								69
 
								70
 
								71
 
								72
 
								73
 
								74
 
								75
 
								76
 
								77
 
								78
 
								79
 
								80
 
								81
 
								82
 
								83
 
								84
						 | <?php/*** * @name php备份数据库 * @param string $DbHost 连接主机* @param string $DbUser 用户名* @param string $DbPwd 连接密码* @param string $DbName 要备份的数据库* @param string $saveFileName 要保存的文件名, 默认文件保存在当前文件夹中,以日期作区分* @return Null* @example backupMySqlData('localhost', 'root', '123456', 'YourDbName');**/functionbackupMySqlData($DbHost, $DbUser, $DbPwd, $DbName, $saveFileName= ''){header("Content-type:text/html;charset=utf-8");error_reporting(0);set_time_limit(0);echo'数据备份中,请稍候......<br />';$link= mysql_connect($DbHost, $DbUser, $DbPwd) ordie('数据库连接失败: '. mysql_error());mysql_select_db($DbName) ordie('数据库连接失败: '. mysql_error());mysql_query('set names utf8');// 声明变量$isDropInfo= '';$insertSQL= '';$row= array();$tables= array();$tableStructure= array();$fileName= ($saveFileName? $saveFileName: 'MySQL_data_bakeup_') . date('YmdHis') . '.sql';// 枚举该数据库所有的表$res= mysql_query("SHOW TABLES FROM $DbName");while($row= mysql_fetch_row($res)) {$tables[] = $row[0];}mysql_free_result($res);// 枚举所有表的创建语句foreach($tablesas$val) {$res= mysql_query("show create table $val", $link);$row= mysql_fetch_row($res);$isDropInfo= "DROP TABLE IF EXISTS `". $val. "`;\\r\\n";$tableStructure= $isDropInfo. $row[1] . ";\\r\\n";file_put_contents($fileName, $tableStructure, FILE_APPEND);mysql_free_result($res);}// 枚举所有表的INSERT语句foreach($tablesas$val) {$res= mysql_query("select * from $val");// 没有数据的表不执行insertwhile($row= mysql_fetch_row($res)) {$sqlStr= "INSERT INTO `".$val."` VALUES (";foreach($rowas$v){$sqlStr.= "'$v',";}//去掉最后一个逗号$sqlStr= substr($sqlStr, 0, strlen($sqlStr) - 1);$sqlStr.= ");\\r\\n";file_put_contents($fileName, $sqlStr, FILE_APPEND);}mysql_free_result($res);}echo'数据备份成功!';}   // 调用此方法 backupMySqlData('localhost', 'root', '123456', 'YouDbName'); ?> | 
以上所述就是本文的全部内容了,希望大家能够喜欢。
相关文章
             猜你喜欢
        
        - 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
			TA的动态
			
		
				- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
				您的支持,是我们最大的动力!				
			
		
        热门文章
        
    
    - 
            2025-06-04 96
- 
            2025-06-04 80
- 
            2025-05-27 102
- 
            2025-05-29 91
- 
            2025-06-04 39
		热门评论
	
	 
        
 
    		 
            	 
															 
         
        
 
                        