MySql BACKUP with PHP...?

Discussion in 'PHP' started by vagelism, Sep 6, 2008.

  1. #1
    Hello to all .
    I use the code below to make a backup of my tables in my database.
    The problem is that the backup is generated in the mysql directory(the same one as the original database)
    Any ideas to alter the code in order to have the back up in my project directory under backup subfolder?
    Because i make a share code for my job anyone can have the project in different directories...

    THANK YOU FOR YOUR TIME.

    //THE CODE

    <?php
    require_once("includes/connections.php");
    require_once("includes/constants.php");

    ?>
    <html>
    <head>
    <title>Εγγραφή Δεδομένων</title>
    </head>
    <body>
    <?php
    $tableName = array("monades", "elements");

    $a=0;
    while ($a<2) {$pinakas=$tableName["$a"];
    $backupFile = "{$pinakas}".".sql";
    $query = "SELECT * INTO OUTFILE '$backupFile' FROM $pinakas";
    $result = mysql_query($query); global $a;
    $a++ ;
    }

    ?>


    <?php
    include("includes/close_connection.php");
    ?>
    </body>
    </html>
     
    vagelism, Sep 6, 2008 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    May be try this to backup in current folder then move the file

    Moving file to required location


    But requires testing.

    regards
     
    Vooler, Sep 7, 2008 IP
  3. vagelism

    vagelism Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thid seems to work fine for me but how i will make it to work if some one has changed the Working directory
    for example instead of C:/wamp/www/STANDARIZATION
    C:/wamp/www/ISO


    <?php
    $tableName = array("monades", "elements");

    $a=0;
    while ($a<2) {$pinakas=$tableName["$a"];
    $backupFile = "{$pinakas}".".sql";
    $query = "SELECT * INTO OUTFILE '$backupFile' FROM $pinakas";
    $result = mysql_query($query); global $a;
    rename("C:/wamp/bin/mysql/mysql5.0.51b/data/db_army/$backupFile ", "C:/wamp/www/STANDARIZATION/backup/$backupFile");
    $a++ ;
    }

    ?>
     
    vagelism, Sep 7, 2008 IP