• 04-06-2019, 03:53:36
    #1
    <?php
    
    function backupDatabaseTables('localhost','root','root','proje2');{
    //veritabanı bağlantısı
    $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
    
    //tüm tabloları alalım
    if($tables == '*'){
    $tables = array();
    $result = $db->query("SHOW TABLES");
    while($row = $result->fetch_row()){
    $tables[] = $row[0];
    }
    }else{
    $tables = is_array($tables)?$tables:explode(',',$tables);
    }
    
    //tablolar içerisinde dönelim
    foreach($tables as $table){
    $result = $db->query("SELECT * FROM $table");
    $numColumns = $result->field_count;
    
    $return .= "DROP TABLE $table;";
    
    $result2 = $db->query("SHOW CREATE TABLE $table");
    $row2 = $result2->fetch_row();
    
    $return .= "nn".$row2[1].";nn";
    
    for($i = 0; $i < $numColumns; $i++){
    while($row = $result->fetch_row()){
    $return .= "INSERT INTO $table VALUES(";
    for($j=0; $j < $numColumns; $j++){
    $row[$j] = addslashes($row[$j]);
    $row[$j] = ereg_replace("n","\n",$row[$j]);
    if (isset($row[$j])) { $return .= '"'.$row[$j].'"' ; } else { $return .= '""'; }
    if ($j < ($numColumns-1)) { $return.= ','; }
    }
    $return .= ");n";
    }
    }
    
    $return .= "nnn";
    }
    
    //dosyayı kaydedelim
    $handle = fopen('db-backup-'.time().'.sql','w+');
    fwrite($handle,$return);
    fclose($handle);
    }
    ?>


    nasıl çözerim arkadaşlar
  • 04-06-2019, 06:05:40
    #2
    <?php
    
    function backupDatabaseTables($dbHost,$dbUsername,$dbPassword,$dbName,$tables = '*'){
    //connect & select the database
    $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
    
    //get all of the tables
    if($tables == '*'){
    $tables = array();
    $result = $db->query("SHOW TABLES");
    while($row = $result->fetch_row()){
    $tables[] = $row[0];
    }
    }else{
    $tables = is_array($tables)?$tables:explode(',',$tables);
    }
    
    //loop through the tables
    foreach($tables as $table){
    $result = $db->query("SELECT * FROM $table");
    $numColumns = $result->field_count;
    
    $return .= "DROP TABLE $table;";
    
    $result2 = $db->query("SHOW CREATE TABLE $table");
    $row2 = $result2->fetch_row();
    
    $return .= "nn".$row2[1].";nn";
    
    for($i = 0; $i < $numColumns; $i++){
    while($row = $result->fetch_row()){
    $return .= "INSERT INTO $table VALUES(";
    for($j=0; $j < $numColumns; $j++){
    $row[$j] = addslashes($row[$j]);
    $row[$j] = ereg_replace("n","\n",$row[$j]);
    if (isset($row[$j])) { $return .= '"'.$row[$j].'"' ; } else { $return .= '""'; }
    if ($j < ($numColumns-1)) { $return.= ','; }
    }
    $return .= ");n";
    }
    }
    
    $return .= "nnn";
    }
    
    //save file
    $handle = fopen('db-backup-'.time().'.sql','w+');
    fwrite($handle,$return);
    fclose($handle);
    }
    
    
    // Kullanımı
    backupDatabaseTables('localhost','root','sifre','dbadi');
    
    
    ?>
  • 04-06-2019, 06:30:29
    #3
    İşini görürse daha önce şöyle bir şey kodlamıştım, ftp dosyaları ve mysql backup almak için php script.

    https://github.com/mrtplt024/easync-backup