-
-
//Fast Mysql big data backup - //Before use, please first modify the SQL file name, database host name, database user name, and password to be imported according to the code comments ,Database name.
- //At the same time, ftp the database file and text into the website directory, and then access this file in WEB mode
- //edit: bbs.it-home.org
- $file_name="bn_site.sql";//To be imported SQL file name
- $dbhost="localhost";//Database host name
- $dbuser="root";//Database user name
- $dbpass="";//Database password
- $dbname="bn_site"; // Database name
- set_time_limit(0);//Set the timeout to 0, which means it will always be executed. When php is invalid in safe mode, the import will time out. At this time, it needs to be imported in sections
- $fp=@fopen($file_name,"r") or die ("Cannot open SQL file");//Open the file
- mysql_connect($dbhost,$dbuser,$dbpass) or die("Cannot connect to database"); //Connect to database
- mysql_select_db($dbname) or die("Cannot open database"); //Open database
- echo "is Execute import operation";
- while($SQL=GETNEXTSQL()){
- if(!mysql_query($sql)){
- echo "Execution error: ".mysql_error()." font>
";
- echo "The SQL statement is:
".$SQL." ";
- };
}
- echo "Import completed ";
fclose($fp) or die ("can"t close file $file"); //Close the file
- mysql_close();
- //From file Get SQL item by item in
- function GETNETSQL(){
- global $fp;
- $sql="";
- while( $line=@fgets($fp,40960)){
- $line=trim($line);
- / /The following three sentences are not needed in higher versions of PHP, but may need to be modified in some lower versions.
- $line = str_replace("\\","\",$line);
- $line = str_replace("'"," '",$line);
- $line = str_replace("\r\n",chr(13).chr(10),$line);
- if (strlen($line)>1){
- if ( $line[0]=="-"&& $line[1]=="-"){
- continue;
- }
- }
$sql.=$line.chr(13 ).chr(10);
- if (strlen($line)>0){
- if ($line[strlen($line)-1]==";"){
- break;
- }
- }
- }
- return $sql;
- }
- ?>
-
Copy code
|