We must have used phpMyAdmin inside the database import, export function, very convenient. But in practical applications, I found the following questions:
1 database more than a certain size, such as 6M at this time using the export generally no problem, you can correctly save to the local hard disk, but the import is not! The reason is: General PHP. INI set temporary file/upload file size limit of 2M, and phpMyAdmin use the way to upload, resulting in failure.
2 exported to the hard drive. SQL file in the lead back, often because of some single quotes problems caused by failure, resulting in the import failure, can only use MySQL and other applications imported. My database is over 10M, so this problem must be addressed. My train of thought:
Export: Save database/table structure with phpMyAdmin, read database content with script and save to file!
Import: Restore the database/table structure with phpMyAdmin, read the file with the script, and save it to the library!
The export process is as follows: Call method ****.php?table=tablename
This simple program saves a table at once!! Each behavior a field of data!!
The
The following is the referenced content: <? if ($table ==\ "\") exit (); mysql_connect (\ "localhost\", \ "name\", \ "password\"); mysql_select_db (\ "database\"); $result = mysql_query (\ "SELECT * from $table \"); if (mysql_num_rows ($result) < = 0) exit (); Echo \ Begins converting data to text ... \ "; $handle = fopen (\ "$table. txt\", \ "w\"); $numfields = Mysql_num_fields ($result); Fputs ($handle, $numfields. \ "\r\n\"); for ($k =0; $k < mysql_num_rows ($result); $k + +) { $msg = mysql_fetch_row ($result); for ($i =0; $i < $numfields; $i + +) { $msg [$i] = Str_replace (\ \r\n\, \ &&php2000mysqlreturn& &\ ", $msg [$i]); $msg [$i] = Str_replace (\ "\n\", \ "&&php2000mysqlreturn&&\", $msg [$i]); Fputs ($handle, $msg [$i].\ "\r\n\"); } fputs ($handle, \ "-------php2000 dump Data program V1.0 for MySQL--------\r\n\"); } Fclose ($handle); echo \ "Ok\"; ? |
The imported programs are as follows: Use the same top!
The following are the referenced contents: <? if ($table ==\ "\") exit (); Mysql_connect ("localhost\", "name\", "password\"); mysql_select_db (\ "database\"); $message = file (\ "$table. txt\"); echo $numfields = Chop ($message [0]); For ($k =1 $k < count ($message); $k + + ($numfields + 1)) { $value =\ "\"; for ($i = $k; $i < ($k + $numfields-1); $i + +) { $tmp = Str_replace (\ "&&php2000mysqlreturn&&\", \ "\r\n\", Chop ($message [$i])); $value. = \ "\ \". Addslashes ($tmp). \ "\ ', \"; } $tmp = Str_replace (\ "&&php2000mysqlreturn&&\", \ "\r\n\", Chop ($message [$k + $numfields-1]); $value. = \ "\ \". $tmp. \ "\"; $query = \ INSERT into $table values (\. $value. \ ") \"; Echo Mysql_error (); mysql_query ($query); echo $k. \ "\"; } echo \ "Ok\"; ?> |
How to use and possible problems!
1 the file () function may have problems while importing (my 10M data is not a problem), you can change to fopen () and not read one line!!
2 Import, export all need to use FTP operation, that is, after the export, with FTP data to the local machine, the first transfer data to the server with FTP!