mysql| Program | Data you must have used the phpMyAdmin inside the database import, export function, very convenient. But in practical applications, I found the following questions:
1, the database exceeds 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 disk. 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!!
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!
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 ("&&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, Import time the file () function may have a problem (my 10M data does not appear to be a problem), you can change to fopen () and then read a 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!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.