Page 1 of 1

Problems with PHP system() function

PostPosted: 19. May 2008 17:26
by Scutchamer
Hi Guys,

When trying to back up a mysql database using

system("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname > $filename", $return);

It fails $return=255 and the apache error log says 'mysqldump' is not recognized as an internal or external command, operable program or batch file.

Using
system("C:\xampp\mysql\bin>mysqldump.exe --opt -h$dbhost -u$dbuser -p$dbpass $dbname > $filename", $return);

'works', well $return=0 but it fails to create the file. There is no error in the log.

I get similar problems with mysql and mysqlimport and I assume the rest of the commands. Are the mysql commands installed in XAMPP and if so, why do I need to give the exact address including.exe, if not how do I install them or which configuration file do I add them to? My xampp installation is located in C:\xampp and DocumentRoot "C:/home" not "C:/xampp/htdocs" as is standard if that is the source of my problems? I've set it up like that to replicate the server the website will be run on normally.

Many thanks!

PostPosted: 19. May 2008 19:11
by Xardas der Dunkle
why do I need to give the exact address including.exe, if not how do I install them or which configuration file do I add them to?


You have to, because Windows search the Applications in the local direcotory and that which are set to the PATH-Enviromental-Variable.

Go on your desktop do a right click on "My Computer" and select Properties.
Select the register card "Advanced" and click on "Enviorement Variables".

Search at the list field "System Variables" for "path".
Click on Edit and add: ";C:\xampp\mysql\bin" (without the ").

Re: Problems with PHP system() function

PostPosted: 20. May 2008 10:26
by ifokkema
Scutchamer wrote:system("C:\xampp\mysql\bin>mysqldump.exe --opt -h$dbhost -u$dbuser -p$dbpass $dbname > $filename", $return);

Also, this example is not valid. C:\xampp\mysql\bin>mysqldump.exe is not a valid path (it contains >). Try C:\xampp\mysql\bin\mysqldump.exe. Plus, include a full path in $filename.

PostPosted: 20. May 2008 11:00
by Dave_L
Also, if you use backslashes (\) as path separators in a quoted string, they must be doubled:

system("C:\\xampp\\mysql\\bin\\mysqldump.exe...")'

But it's simpler to use forward slashes (/):

system("C:/xampp/mysql/bin/mysqldump.exe...");

PHP will interpret the forward slashes correctly for the underlying file system, whether it's Windows or GNU/Linux.

PostPosted: 20. May 2008 14:10
by Scutchamer
Edit-just tried to add bzip2 and gzip but not getting any joy, any suggestions? Didn't want to post twice so edited instead. Many thanks!



Thanks a lot guys, it's sorted now, not really sure where > came from, I guess I lifted it from a website. The environment variable doesn't seem to change much but may do after I restart my computer. I've enclosed everything in single not double quotes as apparently PHP runs things faster that way so my single \ works for the time being.

Thanks every so much for all of your help, saved me a few more hours of googling for what is a pretty simple problem!

PostPosted: 22. May 2008 11:56
by Denisk
Hello
I have a problem with backup of MySQL database too. My php script is:
Code: Select all
$bckp_file = $database.date("Y-m-d-H-i-s").".sql";    
$command = "mysqldump --add-drop-table --add-drop-database -u $user -p $pass $database > $bckp_file";
system ($command);

Firstly was a problem same as Scutchamer's, then I add to the System Variebles the pass to mysqldump.exe:
Code: Select all
C:\wamp\mysql\bin\

I restart my PC and then try to run php script, but in Opera or in IE when I running the script the process of the script is not over, all time is loading. In Windows Task Manager I see mysqldump.exe process is running. I am getting backup file, but it is empty - 0 kb. May bee problem is there are some restrictions in configuration files (such as php.ini) or other? Can somebody help me with this problem?

PostPosted: 22. May 2008 16:11
by ifokkema
Denisk wrote:Firstly was a problem same as Scutchamer's, then I add to the System Variebles the pass to mysqldump.exe:
Code: Select all
C:\wamp\mysql\bin\

C:\wamp\ ?!!??
XAMPP gets installed in C:\xampp\.

PostPosted: 22. May 2008 16:30
by Xardas der Dunkle
ifokkema wrote:
Denisk wrote:Firstly was a problem same as Scutchamer's, then I add to the System Variebles the pass to mysqldump.exe:
Code: Select all
C:\wamp\mysql\bin\

C:\wamp\ ?!!??
XAMPP gets installed in C:\xampp\.


Rubish, you can install xampp everywhere, C:\xampp\ is only the default path.

PostPosted: 23. May 2008 08:00
by ifokkema
Xardas der Dunkle wrote:Rubish, you can install xampp everywhere, C:\xampp\ is only the default path.

Duh, but since xampp is the default and there is very little reason to name it wamp, there is more chance Denisk is actually on the wrong forum.
It surely wouldn't be the first time someone does that :roll: