Professional Web Applications Themes

php exec command failure with mysqldump... | mysql... - PHP Development

Hello all, I am using an OS X 10.37 system with apache 1.3.3, PHP 4.3.6, mysql 4.0.20 I am a newbie programmer with a problem. I am attempting to use php's exec command to copy one database (a template) into another database. My problem is that the exec command fails when attempting to issue mysqldump or other mysql commands. It works for virtually all other system functions such as ls -lan and cat whatever etc. Here is the form of my php command string and the exec: $str = ("mysqldump -u".$someuser." -p".somepassword." --opt -Q databasetemplate | mysql -u".someuser." -p".somepassword." newlycreateddatabase"); ...

  1. #1

    Default php exec command failure with mysqldump... | mysql...

    Hello all,

    I am using an OS X 10.37 system with apache 1.3.3, PHP 4.3.6, mysql
    4.0.20

    I am a newbie programmer with a problem. I am attempting to use php's
    exec command to copy one database (a template) into another database.

    My problem is that the exec command fails when attempting to issue
    mysqldump or other mysql commands. It works for virtually all other
    system functions such as ls -lan and cat whatever etc.

    Here is the form of my php command string and the exec:

    $str = ("mysqldump -u".$someuser." -p".somepassword." --opt -Q
    databasetemplate | mysql -u".someuser." -p".somepassword."
    newlycreateddatabase");

    exec($str, $dary ,$dresult);

    for the above $str, $dary returns an empty array and $dresult is 127.

    The string works perfectly in the terminal.

    It feels like a config issue with php or mysql, but I can't see it.
    Does anybody have a quick fix or better yet an alternative non-system
    specific way of accomplishing this function using standard php
    mysql_query calls?

    grateful for any assitance.

    -fritz
    Fritz Guest

  2. #2

    Default Re: php exec command failure with mysqldump... | mysql...

    "Fritz T. Cat" <invalid> wrote in news:070220050245430703%
    invalid:
     

    It's probably a $PATH issue. Try supplying the full system path to
    mysqldump, e.g. /usr/bin/mysqldump, in the exec call. Also, $someuser and
    $somepassword are missing dollar signs in your example above, but I'm
    guessing that was just a re-typing oversight. If they don't exist in the
    original code, add them in.

    hth

    --

    Bulworth : PHP/MySQL/Unix | Email : str_rot13('arg');
    --------------------------|---------------------------------
    <http://www.phplabs.com/> | PHP scripts, webmaster resources
    Senator Guest

  3. #3

    Default Re: php exec command failure with mysqldump... | mysql...

    In article <24.7.50>, Senator Jay
    Billington Bulworth <arg> wrote:
     
    >
    > It's probably a $PATH issue. Try supplying the full system path to
    > mysqldump, e.g. /usr/bin/mysqldump, in the exec call. Also, $someuser and
    > $somepassword are missing dollar signs in your example above, but I'm
    > guessing that was just a re-typing oversight. If they don't exist in the
    > original code, add them in.
    >
    > hth[/ref]

    You were absolutely correct. It was a path issue. The missing $ were a
    function of too late at the keyboard. My final solution was:

    $str = (DB_PATH."mysqldump -u".$someuser." -p".$somepassword." --opt
    -Q databasetemplate | ".DB_PATH."mysql -u".$someuser."
    -p".$somepassword." newlycreateddatabase");

    exec($str, $dary ,$dresult);

    where:

    define("DB_PATH", "/usr/local/mysql/bin/");

    Thanks again for your input.

    -fritz
    Fritz Guest

Similar Threads

  1. Backup & restore MySQL, not using mysqldump
    By Jerry T in forum PHP Development
    Replies: 2
    Last Post: November 15th, 09:49 PM
  2. exec shell command from php
    By Gal in forum PHP Development
    Replies: 4
    Last Post: October 2nd, 12:54 AM
  3. EXEC command
    By Kevin in forum PHP Development
    Replies: 7
    Last Post: October 1st, 04:43 PM
  4. [PHP] exec command
    By Ray in forum PHP Development
    Replies: 2
    Last Post: October 1st, 02:16 PM
  5. better exec() command
    By steronz in forum PHP Development
    Replies: 1
    Last Post: July 24th, 06:55 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139