Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to backup mydatabase


PHP
public function back() {
      $dbhost = 'localhost:3036';
      $dbuser = 'root';
      $dbpass = '';
      $dbname = 'tawrny_dr';
      $backup_file = $dbname . date("Y-m-d-H-i-s") . '.sql';
      //DO NOT EDIT BELOW THIS LINE
   //Export the database and output the status to the page
      $command = 'mysqldump --opt -h' . $dbhost . ' -u' . $dbuser . ' -p' . $dbpass . ' ' . $dbname . ' > ~/' . $backup_file;
      exec($command, $output = array(), $worked);
      switch ($worked) {
          case 0:
              echo 'Database <b>' . $dbname . '</b> successfully exported to <b>~/' . $backup_file . '</b>';
              break;
          case 1:
              echo 'There was a warning during the export of <b>' . $dbname . '</b> to <b>~/' . $backup_file . '</b>';
              break;
          case 2:
              echo 'There was an error during export. Please check your values:<br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' . $dbname . '</b></td></tr><tr><td>MySQL User Name:</td><td><b>' . $dbname . '</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' . $dbhost . '</b></td></tr></table>';
              break;
      }
      die();
  }


but nothing happens


when i put

if(!exec('cd .')){ die('ERROR: Exec is not available!!!"'); }

it output
ERROR: Exec is not available!!!"
Posted
Updated 15-May-14 3:46am
v3

 
Share this answer
 
Comments
TheSniper105 17-May-14 19:39pm    
Exec is php function

http://au1.php.net/function.exec
Why are you surprised? Seriously if you don't know what is going on you really shouldn't be doing this task because it isn't going to end well.

Read the comment above by CHill and note my next comment.

Anyhow it's your database to kill so go to the php.ini file and check the disable_functions and open_basedir settings, php servers generally are limited to certain directories and some functions are disabled.
 
Share this answer
 
v3
Comments
TheSniper105 17-May-14 19:38pm    
i use wamp ok ? and first step i did is check disabled functions and open_basedir and safe mode not enabled in php.ini so i post question here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900