PHP Backup script fails

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP Backup script fails

Postby rdgreenlaw » 25. September 2010 21:30

Hi,

I have the following PHP code which works as expected on a Linux system with Apache, PHP and MySql installed, but fails on Windows XAMPP.
Code: Select all

<?php

// turn on error reporting
error_reporting(-1);
ini_set('display_errors', true);

// Parameters for BINGO database
$username="user";
$password="password";
$hostname="localhost";
$dbname="bingodata";

// Backup file location
$tmpdir="/home/rdg/backupdb/";

// backup file name will be /home/rdg/backupdb/mybackup.sql

$dbh = mysql_connect($hostname, $username, $password)
        or die("Connection to MSQL failed!");

$selected = mysql_select_db($dbname, $dbh)
        or die("Could not access $dbname database:" . mysql_error() );

// Connection to database is established at this point;

    $prefix = "db_";
    $sqlFile = $tmpDir."mybackup.sql";
    $creatBackup = "mysqldump -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile;
 
        echo "<html><title>Backup Bingo Database</title><body>";
    echo "<center>";
    echo "Bingo Reporting System<p>";
    echo "Backup Bingo Database<p>";
    echo exec($creatBackup)."<p>";
    echo "Backup created "<p>";
?>
</body></html>


This works fine on my Linux system, but XAMPP simply creates a zero length file c:/rdg/home/backupdb/mybackup.sql

Any help will be greatly appreciated.
User avatar
rdgreenlaw
 
Posts: 2
Joined: 16. January 2009 04:58

Re: PHP Backup script fails

Postby JonB » 26. September 2010 14:30

are you getting PHP errors? -

is c:/rdg/home/backupdb/mybackup.sql inside your DocumentRoot?

you may also need an absolute path to mysqldump.exe

:?:
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: PHP Backup script fails

Postby rdgreenlaw » 29. September 2010 03:16

JonB wrote:are you getting PHP errors? -

is c:/rdg/home/backupdb/mybackup.sql inside your DocumentRoot?

you may also need an absolute path to mysqldump.exe

:?:


Thanks for your help, JonB!

I was not receiving any PHP errors, and though the file being created is not in the DocumentRoot, it appeared to be a valid location since the file was being created when the script executed the mysqldump command. This left your last suggestion. I put an absolute path to mysqldump in the script as
Code: Select all
   $creatBackup = "c:/xampp/xampplite/mysql/bin/mysqldump.exe -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile;

This resolved my problem and the backup script is now working as intended.

Roger
Roger D. Greenlaw
User avatar
rdgreenlaw
 
Posts: 2
Joined: 16. January 2009 04:58


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 47 guests