|
-
Jul 12th, 2010, 02:00 PM
#1
Thread Starter
Hyperactive Member
a little confusion
I'm trying to use mysqldump and have the following PHP code
Code:
$username = "root";
$password = "password";
$db = "mydb";
$backpath = "C:\inetpub\wwwroot\site\backups\\" . $db . "-backup-" . date("Y-m-d-H-i-s") . ".sql";
$exec = "mysqldump --user={$username} --password={$password} --quick --add-drop-table --add-locks --extended-insert --lock-tables --all {$db} > $backpath";
exec($exec);
This code apparently does not work though. There are no files saved in that directory after running the code. However, if I run
Code:
mysqldump --user=root --password=password --quick --add-drop-table --add-locks --extended-insert --lock-tables --all mydb > C:\inetpub\wwwroot\site\backups\mydb-backup-2010-07-12-14-53-50.sql
in a command prompt, it works just fine. Any ideas why it won't run through PHP?
Also, safe_mode = Off in my php.ini file
Last edited by half flung pie; Jul 12th, 2010 at 02:56 PM.
 Base 2
Fcnncu"Nqxgu"Lguug##
-
Jul 12th, 2010, 04:44 PM
#2
Re: a little confusion
backslashes are used as an escape character in PHP. PHP things you're trying to save to something like (note that the last slash appears because you escape it):
Code:
C:inetpubwwwrootsitebackups\db-backup-Y-m-d-H-i-s.sql
which will obviously not work out too well. escape the backslashes or switch to forward slashes for your path:
PHP Code:
$backpath = "C:\\inetpub\\wwwroot\\site\\backups\\" . $db . "-backup-" . date("Y-m-d-H-i-s") . ".sql"; $backpath = "C:/inetpub/wwwroot/site/backups/" . $db . "-backup-" . date("Y-m-d-H-i-s") . ".sql";
-
Jul 13th, 2010, 08:19 AM
#3
Thread Starter
Hyperactive Member
Re: a little confusion
I changed the backpath as you stated, but it still does not work. I have an "echo $exec;" right before the exec($exec); that prints
Code:
mysqldump --user=root --password=password --quick --add-drop-table --add-locks --extended-insert --lock-tables --all mydb > C:/inetpub/wwwroot/site/backups/mydb-backup-2010-07-13-09-13-53.sql
But doesn't actually do anything. If I copy that^ and paste it into a command prompt, it works just fine.
 Base 2
Fcnncu"Nqxgu"Lguug##
-
Jul 13th, 2010, 10:18 AM
#4
Re: a little confusion
I copied your script and changed the path accordingly and it worked fine:
PHP Code:
$backpath = "C:/webdev/php/mysqldump/" . $db . "-backup-" . date("Y-m-d-H-i-s") . ".sql"; $exec = "mysqldump --user={$username} --password={$password} --quick --add-drop-table --add-locks --extended-insert --lock-tables --all {$db} > $backpath"; exec($exec);
my guess would be that because you're using IIS, IIS doesn't have permission to write to that directory (or IIS doesn't have the right to execute commands through extensions). I can't really help you out there.
-
Jul 13th, 2010, 11:53 AM
#5
Thread Starter
Hyperactive Member
Re: a little confusion
I figured it had something to do with IIS. I've seen TONS of examples on how to mysqldump through php, and none of them have worked. So I suppose my question is now "How do I get IIS to execute stuff properly?"
 Base 2
Fcnncu"Nqxgu"Lguug##
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|