Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post

    Question mysqldump not dumping in php

    my mysql dump question is

    if i execute this statement from command prompt i get a proper file dumping my database
    mysqldump -h localhost -u account_login -pReplacePasswordHere test > test2010-12-19.sql
    Now the same thing i have made as a php scrip as follows

    PHP Code:
    system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile");
    echo 
    "mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile"
    and out put is
    mysqldump -h localhost -u account_login -pReplacePasswordHere test > test2010-12-19.sql
    So that means i have not given any variables wrong ...

    But when php executes it creates a 0kb file with no output in it. While the original cmd prmt faithfully gives the correct output...

    Whats wrong?

    No warnings are displayed by the way

    PS: while using the optional return code part to check the return code it returned 1

    Changed code =
    PHP Code:
    $xxx system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile",$tmp);
    echo 
    "mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile RETURNED $tmp, ".($xxx?"true":"false"); 
    changed output =
    mysqldump -h localhost -u account_login -pReplacePasswordHere test > test2010-12-19.sql RETURNED 1, false
    Last edited by adarshakb; 12-19-2010 at 08:55 AM.
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #2
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Don't know how to fix, but for some reason I have had a lot of hassle using mysqldump with the -pPassword command, linux and windows. Never seems to work for me, it should according to documentation, so it might be ignoring that option and prompting for password input, in which case your sunk, use an SH script to echo a password to prompt. Or create a user without password if your system allows this, but a huge security risk.
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #3
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    actually that didnot work at all for me

    Finally i used another script from phpclasses website and got the same job done.

    I still need to findout whats wrong with this tho
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Does your provider allow external programs to be run by PHP? Does your installation of PHP have safe_mode enabled?

    The return of false from the system command indicates that the system call is not working. See http://us.php.net/manual/en/function.system.php for more details.

    Have you tried using exec instead of system? If you're doing a DB dump you really shouldn't need anything it might return. I've been using exec via a cron to back up DBs for years without any problems/issues.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    if i use the same system() function to execute ANY other commands and output to a file i am getting proper output.
    The question of hosting doesnt come here as this error is in my local comp AND host

    My safe mode is off
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Try using the full path to mysqldump. You might also have to escape your password if it contains spaces or special characters.

  • #7
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    Try using the full path to mysqldump. You might also have to escape your password if it contains spaces or special characters.
    If i do that how can i execute it on server then(using godaddy)? also i dont have any special characters in password so there is no problem.
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs


  •  

    Posting Permissions

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