Problems with PHP system() function

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Problems with PHP system() function

Postby Scutchamer » 19. May 2008 17:26

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!
Scutchamer
 
Posts: 2
Joined: 19. May 2008 17:12

Postby Xardas der Dunkle » 19. May 2008 19:11

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 ").
User avatar
Xardas der Dunkle
 
Posts: 482
Joined: 09. March 2008 19:40
Location: /var/www

Re: Problems with PHP system() function

Postby ifokkema » 20. May 2008 10:26

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.
ifokkema
 
Posts: 56
Joined: 08. May 2008 13:05
Location: Leiden, Netherlands

Postby Dave_L » 20. May 2008 11:00

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.
User avatar
Dave_L
 
Posts: 212
Joined: 23. October 2004 00:43

Postby Scutchamer » 20. May 2008 14:10

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!
Scutchamer
 
Posts: 2
Joined: 19. May 2008 17:12

Postby Denisk » 22. May 2008 11:56

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?
Denisk
 
Posts: 1
Joined: 22. May 2008 11:35

Postby ifokkema » 22. May 2008 16:11

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\.
ifokkema
 
Posts: 56
Joined: 08. May 2008 13:05
Location: Leiden, Netherlands

Postby Xardas der Dunkle » 22. May 2008 16:30

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.
User avatar
Xardas der Dunkle
 
Posts: 482
Joined: 09. March 2008 19:40
Location: /var/www

Postby ifokkema » 23. May 2008 08:00

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:
ifokkema
 
Posts: 56
Joined: 08. May 2008 13:05
Location: Leiden, Netherlands


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 54 guests