Làm cách nào để sao lưu trong PHP?

Đầu tiên, tôi lấy đối tượng kết nối cơ sở dữ liệu để lấy lược đồ bảng và dữ liệu được kết xuất vào một tệp. Tôi đọc tất cả các tên bảng từ cơ sở dữ liệu và lưu vào một mảng

Trong hướng dẫn này, chúng ta sẽ tìm hiểu cách tạo bản sao lưu cơ sở dữ liệu bằng PHP. Điều này sẽ hoạt động với PHP 7 và các phiên bản cao hơn của nó

Tôi đã viết một hàm để xuất cơ sở dữ liệu ở đây

select_db[$name]; 
        $mysqli->query["SET NAMES 'utf8'"];

        $queryTables    = $mysqli->query['SHOW TABLES']; 
        while[$row = $queryTables->fetch_row[]] 
        { 
            $target_tables[] = $row[0]; 
        }   
        if[$tables !== false] 
        { 
            $target_tables = array_intersect[ $target_tables, $tables]; 
        }
        foreach[$target_tables as $table]
        {
            $result         =   $mysqli->query['SELECT * FROM '.$table];  
            $fields_amount  =   $result->field_count;  
            $rows_num=$mysqli->affected_rows;     
            $res            =   $mysqli->query['SHOW CREATE TABLE '.$table]; 
            $TableMLine     =   $res->fetch_row[];
            $content        = [!isset[$content] ?  '' : $content] . "\n\n".$TableMLine[1].";\n\n";

            for [$i = 0, $st_counter = 0; $i < $fields_amount;   $i++, $st_counter=0] 
            {
                while[$row = $result->fetch_row[]]  
                { //when started [and every after 100 command cycle]:
                    if [$st_counter%100 == 0 || $st_counter == 0 ]  
                    {
                            $content .= "\nINSERT INTO ".$table." VALUES";
                    }
                    $content .= "\n[";
                    for[$j=0; $jquery["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 .= "\n\n".$row2[1].";\n\n";
        for[$i = 0; $i fetch_row[]]{
                $return .= "INSERT INTO $table VALUES[";
                for[$j=0; $j 

Chủ Đề