Home > php教程 > php手册 > php备份mysql数据库源代码

php备份mysql数据库源代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 08:58:19
Original
1189 people have browsed it

php备份mysql数据库源代码,应用时,请把前面系号去掉.

  1. $host="localhost";         
  2. $user="root";      
  3. $password="";        
  4. $dbname="";      
  5. mysql_connect($host,$user,$password);         
  6. mysql_select_db($dbname);       
  7. $mysql= "set charset utf8;rn";           
  8. $q1=mysql_query("show tables");           
  9. while($t=mysql_fetch_array($q1)){      
  10.     $table=$t[0];      
  11.     $q2=mysql_query("show create table `$table`");           
  12.     $sql=mysql_fetch_array($q2);       
  13.     $mysql.=$sql['Create Table'].";rnrn";       
  14.      
  15.     $q3=mysql_query("select * from `$table`");      
  16.     while($data=mysql_fetch_assoc($q3)){      
  17.         $keys=array_keys($data);      
  18.         $keys=array_map('addslashes',$keys);      
  19.         $keys=join('`,`',$keys);         
  20.         $keys="`".$keys."`";        
  21.         $vals=array_values($data);       
  22.         $vals=array_map('addslashes',$vals);        
  23.         $vals=join("','",$vals);       
  24.         $vals="'".$vals."'";      
  25.         $mysql.="insert into `$table`($keys) values($vals);rn";      
  26.     }      
  27.     $mysql.="rn";                   
  28. }      
  29. $filename=date('Ymj').".sql";         
  30. $fp = fopen($filename,'w');         
  31. fputs($fp,$mysql);           
  32. fclose($fp);           
  33. echo "数据备份成功,生成备份文件".$filename."";           



Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template