Re: Timeout problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



can you just use a cron job and mysqlbackup instead? it does what you want and is already written.

Jon

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux