Re: Timeout problem
| From: | Guus der Kinderen | Date: | Mon, 09 Aug 2004 19:42:51 +0000 |
| Subject: | Re: Timeout problem | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35632@lists.php.net to get a copy of this message | ||
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// 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++) {'.$row[0].'VALUES (';// remove all enters from the field-string. MySql stamement must be onone 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!