Import a program that exports large amounts of data from mysql
Author: Zizhu Joined: 2003-11-22 Views: we must use over 184 database import phpmyadmin inside, export functions, very convenient. However, in practical applications, I found that the following issues: 1 database exceeds a certain size, such as 6M use exports generally no problem, can be saved to the local hard drive, but the import is not! The reason is: The general php.ini sets the temporary file / upload file size limit to 2m, and phpMyAdmin uses the uploaded mode, causing failure. 2 Export to the hard disk. SQL files are returned, often occurring failures due to certain single quotes, resulting in failure, and can only be imported with applications such as mysql. My database has exceeded 10M, so this problem must be solved. My Idea: Export: Save the database / table structure with phpMyadmin, read the database content with the script and save it to the file! Import: Recover the database / table structure with phpMyAdmin, read the file with the script, and save it to the library! The export procedure is as follows: call method is ****. PHP? Table = Tablename This simple program currently saves a form! ! Data for each behavior! !
IF ($ TABLE == ") exit (); mysql_connect (" localhost "," name "," password "); mysql_select_db (" database "); $ results = mysql_query (" SELECT * FROM $ TABLE "); if (MySQL_NUM_ROWS ($ RESULT) <= 0) exit (); echo "Start conversion data to text ..."; $ hand = fopen ("$ TABLE.TXT", "W"); $ Numfields = mysql_num_fields ($ Result) FPUTS ($ Handle, $ Numfields. "RN"); for ($ k = 0; $ k)
{
$ msg = mysql_fetch_row ($ result);
For ($ i = 0; $ i <$ number 4; $ i )
{
$ msg [$ I] = STR_REPLACE ("RN", ", $ MSG [$ I]);
$ MSG [$ I] = STR_REPLACE ("N", ", $ MSG [$ I]);
FPUTS ($ HANDLE, $ MSG [$ I]. "RN");
}
FPUTS ($ Handle, "----- PHP2000 Dump Data Program v1.0 for mysql -------- rn");
}
Fclose ($ handle);
Echo "OK";
?>
The imported program is as follows: Usage is above!
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)
{
$ Value = "";
For ($ I = $ K; $ i <($ K $ Numfields-1); $ i )
{
$ TMP = STR_REPLACE ("", "RN", ChOP ($ Message [$ I]));
$ Value. = "'" .addslashes ($ TMP). "',";
}
$ TMP = STR_REPLACE ("RN", 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 methods and possible problems!
1 When the import is imported () function may have problems (my 10M data does not have a problem), can be changed to fopen () and then don't read a line! !
2 Import, export needs to operate with FTP, which is exported, transferring data with FTP to this machine, first use FTP to transfer data to the server!
">">