Dismiss Notice
You are browsing this site as a guest. It takes 2 minutes to CREATE AN ACCOUNT and less than 1 minute to LOGIN

PHP Quick Hacks

Discussion in 'Tech, Gadgets & Science Forum' started by emanuel.feruzi, Oct 5, 2009.

  1. emanuel.feruzi

    emanuel.feruzi Senior Member

    #1
    Oct 5, 2009
    Joined: Apr 25, 2009
    Messages: 103
    Likes Received: 3
    Trophy Points: 0
    I had write a small script to allow someone to do a dump of the MySQL database that was later sent to them by email. It worked very well until we tried it on the productions server that was running on Windows and it broke.

    I have rewritten it so that it works on Windows:-

    PHP:
    <?php
        
    /* variable declaration */
        
    $db_user "yourUsername";
        
    $db_password "yourPassword";
        
    $db_database "yourDatabaseName";
        
    $db_server "yourHostName";    //default: localhost
        
    $backup_path "C:\\path\\to\\backup\\folder\\";
        
    //e.g $backup_path = "C:\\backups\\sqldumps\\";
        
    $path_to_mysqldump "C:\\path\\to\\mysql\\bin\\";
        
    //e.g $path_to_mysqldump = "C:\\xampp\\mysql\\bin\\";
        
    $filename "backup".date("YmdHis").".sql";   //filename with a timestamp
        
        
        /*construction the command to be run */
        
    $command"$path_to_mysqldump\\mysqldump.exe --add-drop-table --add-drop-database -h $db_server -u $db_user --password=$db_password $db_database > $filename "
        
        
    /* excution of the command */    
        
    exec($command$dump$status);    
        
        
    /*checking the status of the command after runing */
        
    if($status!=0){
            echo 
    "The execution was not successfull. An empty file has been created";
        }else{
            echo 
    "The execution was successfull. Backup files is " $backup_path.$filename ;
        }
    ?> 
    I hope some finds this useful.

    Comments are welcome.
     
  2. emanuel.feruzi

    emanuel.feruzi Senior Member

    #2
    Oct 5, 2009
    Joined: Apr 25, 2009
    Messages: 103
    Likes Received: 3
    Trophy Points: 0
Loading...