restore backup mysqldump php

杀马特。学长 韩版系。学妹 提交于 2019-12-12 05:09:24

问题


i can't seem to restore my database backup in php. this is my code

<?php
        $host = 'localhost';
        $user = 'root';
        $pass = ' ';
        $dbname = 'itravel';
        date_default_timezone_set('Asia/Kuala_Lumpur'); 
        $date = date('Y_m_d');
        if(isset($_POST['backup']))
        {
            $backup = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname > itravel_backup_$date.sql";
            system($backup);
        }

        if(isset($_POST['restore']))
        {
            $restore = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname < itravel_backup_$date.sql";
            system($restore);
        }
        ?>

backup was successful but the restore is a failure. help me guys!


updated the code with

<?php
        $host = 'localhost';
        $user = 'root';
        $pass = ' ';
        $dbname = 'itravel';
        //date_default_timezone_set('Asia/Kuala_Lumpur'); 
        //$date = date('Y_m_d');
        $backup_name = 'itravel_backup.sql';
        if(isset($_POST['backup']))
        {
            $backup = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname > $backup_name";
            system($backup);
        }

        if(isset($_POST['restore']))
        {
            //$restore = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname < itravel_backup_$date.sql";
            //system($restore);
            $restore = "c:/xampp/mysql/bin/mysql --opt -h $host -u $user $dbname < $backup_name";
            system($restore);
        }
        ?>

but still not working


回答1:


You need to use the mysql binary to restore, not mysqldump.



来源:https://stackoverflow.com/questions/14799987/restore-backup-mysqldump-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!