Hello Mauro,
There are several scripts available for performing database-backups. You can find more information for mysql here: http://dev.mysql.com/doc/mysql/en/Backup.html
Why re-invent the wheel? Hope this helps.
Regards,
Guus der Kinderen
Mauro Chojrin wrote:
Hi:
I'm developing a db application with php and I have this problem:
I have a script for backup making which is very simple, it just goes through the entire database creating a file which contains the sql statements to re create the database. The first thing the script does y increase the time limit based on a calculation over the total number of records. Every time I ran the script it would time out. After some time reviewing the code (First I thought it might be hanging in an infinite loop) I realized the problem was with a particular big size table. There must be a way to optimize the code, because when I backup the database through phpMyAdmin it works just fine, even fast.
This the cycle that's crashing down:
$fields = mysql_list_fields($dPconfig['dbname'], $row[0]); $columns = mysql_num_fields($fields);
$insertSQL = 'INSERT INTO `'.$row[0].'` VALUES (';
// all data from table $result = mysql_query('SELECT * FROM '.$row[0]);
while($tablerow = mysql_fetch_array($result)) { $output .= $insertSQL; for ($i = 0; $i < $columns; $i++) { // remove all enters from the field-string. MySql stamement must be on one line $value = str_replace("\r\n",'\n',$tablerow[$i]); // replace ' by \' $value = str_replace('\'',"\'",$value); $output .= '\''.$value.'\','; } $output = substr($output,0,-1); // remove last comma $output .= ');' . "\r\n"; } // while
$output .= "\r\n"; $output .= "\r\n"; }
Thanks!
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php