Mysqldump via exec problem 
Author Message
 Mysqldump via exec problem

Hi,
I'm trying to dump a mysql database via an exec call:

$command = "mysqldump -c -t -u user -ppassword database > data.sql";
echo "<p>$command";
echo exec($command);

Now, when I examine the data.sql file it is empty.  If I run the command
from the shell as outputted in line 2 of my little code snippet, it works
great.  However, I must delete the empty data.sql file first as it is owned
by the www user, and not my user that I am logged in as.  Could there be
some sort of permissions problem which won't allow me to dump the output to
a file?  Any ideas would be greatly appreciated..

Thanks,
Jk



Sun, 31 Jul 2005 15:06:35 GMT  
 Mysqldump via exec problem

Quote:

> Could there be some sort of permissions problem which won't allow me to
> dump the output to a file?  Any ideas would be greatly appreciated..

Erm, yes!  You need to ensure that either:

i) if the file exists, you have write access
ii) if the file doesn't exist you have write access to .

Regards,

David

--
David Jonathan Grant
http://www.davidjonathangrant.info/



Sun, 31 Jul 2005 17:59:46 GMT  
 Mysqldump via exec problem

Quote:
> Hi,
> I'm trying to dump a mysql database via an exec call:

> $command = "mysqldump -c -t -u user -ppassword database > data.sql";
> echo "<p>$command";
> echo exec($command);

Hi Jonathan,

Have you tried using the full path to mysqldump? E.g:

$command = "/usr/local/mysql/bin/mysqldump -c -t -u user -ppassword database

Quote:
> data.sql";

JOn


Sun, 31 Jul 2005 19:05:30 GMT  
 Mysqldump via exec problem

Quote:
Jonathan Kart wrote...
> Hi,
> I'm trying to dump a mysql database via an exec call:

> $command = "mysqldump -c -t -u user -ppassword database > data.sql";
> echo "<p>$command";
> echo exec($command);

I think windows has a few problems with redirection in a embedded command

try this:
  exec($command, $output);
  $f = fopen('data.sql', 'w');
  fwrite($f, implode("\n", $output));
  fclose($f);

Hope this helps



Sun, 31 Jul 2005 20:16:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Tcl/TK command via exec returns nothing

2. passing cmd line options via exec

3. .bat-execution via exec is aborted if command writes to stderr

4. initializing private members via exec

5. running a program via exec*

6. printing via exec

7. Using mysqldump from Php

8. exec and interactive exec differences

9. using exec in windows nt exec on tcl scripts

10. Exec not exec-ing sh scripts in tcl 7.5b1

11. Problem with J files via ftp?

12. Problem loading parcels via command-line options

 

 
Powered by phpBB® Forum Software