labrat
02-07-2005, 09:42 PM
I have a php program that is trying to create a backup file of data of a MySQL database. I didn't write this code and there are so many includes, I'm not sure where to look for the problem. When I run the code, I get "Cannot open file backups/tng_sources.bak". Now, there is a config file where I set the $rootpath and $backuppath and they are set as "/home/[hrbasedomain]/public_html/genealogy/" and "backups" respectively so I'm not sure why the error msg seems to exclude the $rootpath part.
foreach( $tablelist as $table ) {
$filename = "$rootpath$backuppath/$table.bak";
if( file_exists( $filename ) ) unlink( $filename );
$fp = @fopen( $filename, "w" );
if( !$fp ) { die ( "$admtext[cannotopen] $filename" ); }
flock( $fp, LOCK_EX );
$nextchunk = -1;
$numrows = 0;
do {
$nextone = $nextchunk + 1;
$nextchunk += $largechunk;
$query = "SELECT * FROM $table LIMIT $nextone, $largechunk";
$result = mysql_query($query) or die ("$admtext[cannotexecutequery]: $query");
if( $result ) {
$numrows = mysql_num_rows( $result );
while( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) {
$line = "";
for( $i = 0; $i < sizeof( $row ); $i++ ) {
if( $line ) $line .= ",";
$element = addslashes( $row[$i] );
$line .= "\"$element\"";
}
$line .= "\n";
fwrite( $fp, "$line" );
}
mysql_free_result( $result );
}
} while ( $numrows );
flock( $fp, LOCK_UN );
fclose( $fp );
}
I have a server set up on my home machine (WinXP/Apache/PHP/MySQL) and I tried it there. It has no problem running on my local setup (but the rootpath is "C:\Web\localhost\genealogy) so I was wondering if it might be a permissions error. Of course there are other variables that are different so I'm not sure.
Please let me know if you can point me in the right direction or if I left out any important details.
TIA,
-labrat
foreach( $tablelist as $table ) {
$filename = "$rootpath$backuppath/$table.bak";
if( file_exists( $filename ) ) unlink( $filename );
$fp = @fopen( $filename, "w" );
if( !$fp ) { die ( "$admtext[cannotopen] $filename" ); }
flock( $fp, LOCK_EX );
$nextchunk = -1;
$numrows = 0;
do {
$nextone = $nextchunk + 1;
$nextchunk += $largechunk;
$query = "SELECT * FROM $table LIMIT $nextone, $largechunk";
$result = mysql_query($query) or die ("$admtext[cannotexecutequery]: $query");
if( $result ) {
$numrows = mysql_num_rows( $result );
while( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) {
$line = "";
for( $i = 0; $i < sizeof( $row ); $i++ ) {
if( $line ) $line .= ",";
$element = addslashes( $row[$i] );
$line .= "\"$element\"";
}
$line .= "\n";
fwrite( $fp, "$line" );
}
mysql_free_result( $result );
}
} while ( $numrows );
flock( $fp, LOCK_UN );
fclose( $fp );
}
I have a server set up on my home machine (WinXP/Apache/PHP/MySQL) and I tried it there. It has no problem running on my local setup (but the rootpath is "C:\Web\localhost\genealogy) so I was wondering if it might be a permissions error. Of course there are other variables that are different so I'm not sure.
Please let me know if you can point me in the right direction or if I left out any important details.
TIA,
-labrat