Guide from MySQL derive the program of mass data implements a method
Tuesday, March 03, 2009 by rain
1 database exceeds certain measure,For instance 6M is used at this moment derive be no problem commonly,Can save this machine hard disk correctly above,But guide be no good!The reason is:Install inside general PHP.INI temporarily file / the size limitation that uploads a file is 2M,And Phpmyadmin used uploading means,Cause failure.
2 derives the.SQL file of hard disk is in guide when answering,Because the problem of certain only quote causes failure,often appear,Cause guide into failure,Can guide with the applied process such as Mysql only.
My database has exceeded 10M, must solve this problem so.My train of thought:
Derive:Save a database with Phpmyadmin / form structure,Read access to save a file according to library content with script inside!
Guide:Restore a database with Phpmyadmin / form structure,Read with script take a file,Save a library next inside!
Derive the program is as follows:Call a method to be ****.php? Table=tablename
This simple procedure saves a form at present!!Every behavior the data of a field!!
%26lt;? If($table==\"\")exit();Mysql_connect(\"localhost\" , \"name\" , \"password\");Mysql_select_db(\"database\");
$result = Mysql_query(\"select * From $table\");If(mysql_num_rows($result)%26lt;= 0) Exit();Echo \" begins to change data to text. . .
\";
$handle = Fopen(\"$table.txt\" , \"w\");
$numfields = Mysql_num_fields($result);Fputs($handle, $numfields. \"\r\n\");For($k=0;$k%26lt;Mysql_num_rows($result);$k++ )
{
$msg = Mysql_fetch_row($result);For($i=0;$i%26lt;$numfields;$i++ )
{
$msg[$i] = Str_replace(\"\r\n\" , \%26quot;%26amp;%26amp;php2000mysqlreturn%26amp;%26amp;\%26quot; , $msg[$i]);
$msg[$i] = Str_replace(\"\n\" , \%26quot;%26amp;%26amp;php2000mysqlreturn%26amp;%26amp;\%26quot; , $msg[$i]);Fputs($handle, $msg[$i] . \"\r\n\");
}Fputs($handle, \ "-------Php2000 Dump Data Program V1.0 For MySQL--------\r\n\");
}Fclose($handle);Echo \"ok\";
? %26gt;
The program that guides is as follows:Usage is Alexandrine face!
%26lt;? 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%26lt;Count($message);$k+=($numfields+1) )
{
$value=\"\";For ($i=$k;$i%26lt;($k+$numfields-1);$i++ )
{
$tmp = Str_replace(\%26quot;%26amp;%26amp;php2000mysqlreturn%26amp;%26amp;\%26quot; , \"\r\n\" , chop($message[$i]));
$value. = \"\'\".addslashes($tmp) . \"\' , \";
}
$tmp = Str_replace(\%26quot;%26amp;%26amp;php2000mysqlreturn%26amp;%26amp;\%26quot; , \"\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\";
? %26gt;
Use method and potential problem!
1 guides fashionable File() function may have a problem (the data of my 10M does not have occurrence problem) ,Can instead Fopen() is done not have next second read group!!
2 guides,Derive need to be operated with Ftp,After deriving namely,Turn data to this machine with Ftp,Guide fashionable use Ftp to transfer data to the server first!