system(mysqldump ....) no output - SOLVED

 
Post new topic   Reply to topic    Aprelium Forum Index -> General Questions
View previous topic :: View next topic  
Author Message
ywfbi
-


Joined: 13 Nov 2005
Posts: 3

PostPosted: Sun Nov 13, 2005 1:05 am    Post subject: system(mysqldump ....) no output - SOLVED Reply with quote

Hi guys, Ive been trying to get this script working for a few days now, its part of a CMS which allows (well should allow) the remote user to download a sqldump of the database.
Code:
<?php
$hostname = "localhost";
$database = "site";
$username = "root";
$password = "*******";
$backupFile = 'backup/'.date("Y-m-d") . '.txt';

$command = "mysqldump -h$hostname -u$username -p$password --databases $database > $backupFile";
//$command = "echo 'this is the backup file' > $backupFile";
system($command);

download($backupFile);
//unlink($backupFile);

function download($file)
{
   $new_len = 0;
   $len     = 0;
   if (file_exists($file))
   {
      $len = getFilesize($file);
      do   { //this do loop checks the backup file has stopped changing filesize before attempting to download it

         sleep(1);
         $new_len = getFilesize($file);
         if ($new_len > $len )
            {$len = $new_len;}
         elseif (($new_len == $len)&&($new_len != 0))
            break;
      }while ($len > 0);

      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Cache-Control: public");
      header("Content-Description: File Transfer");
      header("Content-Type: text/plain"); //application/gzip");
      header("Content-Disposition: attachment; filename=$file;");
      header("Content-Transfer-Encoding: binary");
      header("Content-Length: ".$len);
      @readfile($file);
   }
   else {echo "can't find file. Please check the path and permissions to ensure you can write the file";}
}

function getFilesize($file)
{
   $fs = 0;
   $fs = filesize($file);
   return $fs;
}
?>


Well the actual problem is here, posted whole script for relevance.
Code:
$command = "mysqldump -h$hostname -u$username -p$password --databases $database > $backupFile";
//$command = "echo 'this is the backup file' > $backupFile";
system($command);

If I set the command to echo some text it works fine, however the mysqldump doesn't work. A file is created but remains empty. The path to mysqldump is in the enviroment vars, it works fine from a dos prompt, and in the sql shell. Any ideas folks? Any suggestions would be greatly appreciated.


Last edited by ywfbi on Mon Nov 14, 2005 11:17 am; edited 1 time in total
Back to top View user's profile Send private message
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Nov 13, 2005 1:25 am    Post subject: Reply with quote

What does:
Code:
echo "mysqldump -h$hostname -u$username -p$password --databases $database";

:put into a dos prompt window do? (I.E. The result of that, not actually that.)

Sorry if I'm treating you like a scriptkiddie or something.

Edit: Tired; forgot to remove the stdout.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
ywfbi
-


Joined: 13 Nov 2005
Posts: 3

PostPosted: Sun Nov 13, 2005 2:44 am    Post subject: Reply with quote

MonkeyNation wrote:
What does:
Code:
echo "mysqldump -h$hostname -u$username -p$password --databases $database";

:put into a dos prompt window do? (I.E. The result of that, not actually that.)

Sorry if I'm treating you like a scriptkiddie or something.


Script kiddie, well Ive been called worse!
It would seem I havnt explained myself well enough. Either way I have finally found out where I was going wrong!!!... PHP was in safe mode, I moved mysqldump.exe to the dir and everything worked fine. Which is only a problem when hosted on my local machine, not after uploading. Either that or I havn't configured Abyss to find the path correctly. Not sure.

To kind of answer your question
Code:
mysqldump -h localhost -u username -p password --databases database > filename

in a dos prompt will perform a complete backup of my sql db. What I meant by the dos and sql parts was meant to indicate that the sql was working fine, however I believed the problem resided in PHP. Which it turned out to be the case.
Sorry I really should have phrased my question more carefully.
Back to top View user's profile Send private message
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Nov 13, 2005 3:02 am    Post subject: Reply with quote

I wasn't sure how much you'd tried, no worries.
And if you thought I was calling you a scriptkiddie, I wasn't.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
ywfbi
-


Joined: 13 Nov 2005
Posts: 3

PostPosted: Mon Nov 14, 2005 11:17 am    Post subject: Reply with quote

no probs matey, I really didnt explain myself very well, and I didn't take offence. Believe me Id tried heaps!! After 2 days of trying I posted it to a forum, well this was the second. But its all a learning curve. Surprise surprise the answer was in the php manual, it wasn't until Id read it for about the 4th time that I actually realised it though.
The whole checking $len for changes was to rule out a timing issue, which turned out to be in vain since php is halted during a system command. Like I said it's all a learning curve!
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> General Questions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group