SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP to execute a program

    Hey everyone,

    I'm trying to use PHP to execute a script, specifically mysqldump. Here is the main part of the script:
    PHP Code:
    system("mysqldump -ujamesus -ppass database template > /home/jamesus/public_html/admin/build/templates.sql");

    $templatesql fopen("/home/jamesus/public_html/admin/build/templates.sql""r"); 
    But it doens't seem to be executing properly. I've also tried using the exec() function, which yields similar results.
    No errors, warnings etc are produced and it just moves on to my fopen command, which shows the error that it can't find the file. I then need to do some manipulation within that file and echo it out or email it.

    Thanks in advance for any help you can offer!

    James.
    Last edited by James; Jul 7, 2001 at 03:39.

  2. #2
    SitePoint Enthusiast Stallion's Avatar
    Join Date
    Jan 2001
    Location
    Cumberland, RI, US
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may be because PHP's "environment" is limited. When logged into via telnet/ssh, type "env".

    One of the names should read "PATH", with the value of something similar to "/usr/local/jdk/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin"

    MySQL dump, for me, is located in /usr/bin/, and since /usr/bin/ is located in my environment's PATH, I can simply type mysqldump to access it.

    However, your PHP user (whatever Apache runs as) may have more a limited environment. Try using the full path in place of just "mysqldump", so maybe:
    PHP Code:
    system("/usr/bin/mysqldump -ujamesus -ppass database template > /home/jamesus/public_html/admin/build/templates.sql"); 
    This would depend on where mysqldump is located, but you can find out via "locate mysqldump".

    If that still doesnt work, try echoing the results of the command to the browser.

    PHP Code:
    exec("mysqldump -ujamesus -ppass database template > /home/jamesus/public_html/admin/build/templates.sql"$temp);
    echo 
    $temp


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •