PDA

View Full Version : Using the system function


trafficg
05-14-2001, 05:49 PM
Hi

I have been using Telnet now for a while to backup my database and decided I would write something in PHP to allow me to create/restore database backups more easily.

The PHP script uses the system function and calls the same commands I use with Telnet. I tested the script on my local machine and everything works like a dream, but the script will not work when I upload it.

Sample of code:


$command = "mysqldump $myoptions --u=$username --p=$password -h$host $db_name $table_name > $backup_dir$filename";

system ($command,$myret);


I have tried altering the paths to the various files needed etc. but it always fails, I suspect I am dealing with yet[nbsp][nbsp]another SAFE MODE issue.

Any help would be most welcome.

Pete Kelly

Arthur
05-14-2001, 06:09 PM
You're right, in Safe Mode you can't execute other programs and that's what you're trying to do.

Arthur

Terra
05-14-2001, 06:25 PM
The system(), popen() PHP functions are restricted commands not available for site owner use within the Apache module...[nbsp][nbsp]This is as it should be for your protection, and of others as well...

However, you can use PHP as a CGI to accomplish this since it will run under the proper user id then...[nbsp][nbsp]Any ways, trying to run this via the web will not give you what you want as the files will be owned by 'apache' and not you...[nbsp][nbsp]Going the CGI route will ensure proper permissions/ownership...

If you look around on the forums, there are already solutions for backup up MySQL Databases that other site owners have written...

Maybe someone will step forward and bundle it up into a downloadable package with instructions...[nbsp][nbsp]:)

--
Terra
--never assume that your server is built for handling thousands of accounts--
FutureQuest

trafficg
05-14-2001, 07:07 PM
>>Going the CGI route will ensure proper permissions/ownership...<<

How do you convert the script so it uses the cgi version of PHP? I seem to remember that is was just a matter of adding an extra line to the top of the script.

Pete