ifsnop / mysqldump-php

PHP version of mysqldump cli that comes with MySQL
https://github.com/ifsnop/mysqldump-php
GNU General Public License v3.0
1.25k stars 300 forks source link

how i can auto download dump file #207

Closed vahidalvandi closed 4 years ago

vahidalvandi commented 4 years ago

hi , please help me how i can dump file ?

garas commented 4 years ago

You should be able to php://output as output file to send contents directly to browser.

You may need to send Content-Disposition: attachment; filename="dump.sql" header to trigger download.

vahidalvandi commented 4 years ago

please show me with this code


<?php

use Ifsnop\Mysqldump as IMysqldump;

try {
    $dump = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');
    $dump->start('storage/work/dump.sql');
} catch (\Exception $e) {
    echo 'mysqldump-php error: ' . $e->getMessage();
}
garas commented 4 years ago

use Ifsnop\Mysqldump as IMysqldump;

header('Content-Type: text/plain;charset=utf-8');
header('Content-Disposition: attachment; filename="dump.sql"');

try {
    $dump = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');
    $dump->start('php://output');
} catch (\Exception $e) {
    echo 'mysqldump-php error: ' . $e->getMessage();
}
vahidalvandi commented 4 years ago

thank you