Quick question about PHP script
2 hours ago, I absolutely have no idea how to program in PHP. I took a PHP crash course, because I need to back up my website database. The hosting provider doesnt provide any front end application, so I create a PHP script:
$sqlFile = $dbname . date(".d-m") . '.sql'; $zipFile = $sqlFile . '.zip'; $dumpCommand = "mysqldump -h$host -u$dbuser -p$dbpword $dbname > $sqlFile"; system($dumpCommand); system("zip $zipFile $sqlFile");
Pls shed some light. I have spent more than 1 hour, but havent worked out how to fix it
The power of plain text? It can control an entire OS
for one thing, you might actually try checking for errors....
You've said nothing about your webhost, so there is nothing that anyone here can assume about the execution environment.
system() returns the last line of output on success, false on error. Also because of being a (server side) web scripting language, it has security that can be set up --- safe mode ! When safe mode is enabled, the command is escaped, killing shell specials (e.g. > becomes \>). Safe mode can also be used to restrict the commands that can be executed by PHP scripts.
If zip is failing, it's quite possible that either:
A.) zip/mysqldump is not installed,
B.) zip/mysqldump is not in your search path (or safe_mode_exec_dir),
C.) You do not have permission to execute the program(s),
D.) the arguments are wrong (e..g you can execute zip, but mysqldump args \> file failed)
I don't know MySQL enough to know what access controls may be placed on a user trying to mysqldump their own data, but if it's possible to restrict that, it could be set that way on your host.
When it comes to learning PHP, if you go to the documentation and read the 'Language Reference' section, you've learned most anything you need to know.
Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Last edited by TerryP; 20th September 2008 at 06:26 PM.
|Thread||Thread Starter||Forum||Replies||Last Post|
|Quick, simple tcsh tips for beginners||anomie||Guides||9||6th November 2014 03:55 PM|
|external drive partition question + fdisk question||gosha||OpenBSD General||15||15th June 2009 02:00 PM|
|Quick Ant Question||disappearedng||FreeBSD General||0||27th October 2008 06:20 AM|
|Networking: CLI quick reference||anomie||Other BSD and UNIX/UNIX-like||0||2nd October 2008 01:21 AM|
|quick question about optimizations in /etc/make.conf||thevirtuesofxen||FreeBSD Installation and Upgrading||7||15th July 2008 10:29 AM|