You must have used the database import and export function in phpmyadmin to import and export a large number of data programs. However, in practical application, I found the following problems:
1. the size of the database exceeds a certain size. for example, if the size of 6 MB is used for export, the database can be correctly saved to the hard disk of the local machine, but cannot be imported! The reason is: the size of temporary files/uploaded files is limited to 2 MB in PHP. INI, while phpmyadmin uses the upload method, resulting in a failure.
2. when importing the. SQL file exported to the hard disk back, the import may fail due to some single quotation marks, which can only be imported using applications such as mysql. My database has exceeded 10 MB, so this problem must be solved. My ideas:
Export: use phpmyadmin to save the database/table structure, use scripts to read the database content, and save it to a file!
Import: use phpmyadmin to restore the database/table structure, use scripts to read files, and save them to the database!
The export program is as follows: the call method is ***. php? Table = tablename
This simple program currently saves a table at a time !! Data of one field for each behavior !! Reference content is as follows:
<?
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/"start to convert data to text...
/";
$ Handle = fopen (/"export 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 program is as follows: the usage is the same as above! Reference content is as follows:
<?
If ($ table =/"/") exit ();
Mysql_connect (/"localhost/",/"name/",/"password /");
Mysql_select_db (/"database /");
$ Message = file (/"Your 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 /";
?>
Usage and possible problems!
1. the file () function may be faulty during import (my 10 M data is normal). you can change it to fopen () and then read a row once !!
2. ftp is required for both import and export. after export, ftp is used to transfer the data to the local machine. ftp is used to transfer the data to the server before import!