Backup MySQL database with CodeIgniter

前端 未结 15 1526
一生所求
一生所求 2020-12-30 06:39

I have been looking into the user guide which came with CodeIgniter. I became very interested with the dbutil() method. Particularly the following line of code:

15条回答
  •  独厮守ぢ
    2020-12-30 07:18

    Try this!

    $username = "root";
    $password = "root";
    $hostname = "localhost";
    $dbname   = "raas";
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($dbname . "_" .date("Y-m-d_H-i-s").".sql"));
    
    $command = "C:\AppServ\MySQL\bin\mysqldump --add-drop-table --host=$hostname   --user=$username --password=$password ".$dbname;
    
    system($command);
    

提交回复
热议问题