导出的数据库转储文件不正确


Exported Database Dumpfile Incorrect

我正在尝试创建一个带有按钮的页面,单击该按钮将下载名为sampledb的数据库。

这是我的backup.php

<?php
ob_start();
$username = "root";
$password = "";
$hostname = "localhost";
$dbname   = "sampledb";
$command = "C:''wamp''bin''mysql''mysql5.5.24''bin''mysqldump --add-drop-table --host=" . $hostname . "--user=". $username ." --password=". $password." ".$dbname;
system($command);
$dump = ob_get_contents();
ob_end_clean();
// send dump file to the output
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=sqlfile.sql');
readfile('sqlfile.sql');
flush();
echo $dump;
exit();
?>

出口成功。然而,当我检查下载文件夹中的下载文件(sqlfile.sql)时,它的文件大小只有2kB。我尝试使用phpMyAdmin导出sampledb,发现实际文件大小为9kB。

此外,当我尝试通过phpMyAdmin导入sqlfile.sql时,我收到了一条错误消息。上面写着Warning: readfile(sqlfile.sql)

我的导出代码有问题。有什么建议吗?

更新20131205

我尝试将> sqlfile.sql附加到代码的这一部分。

$command = "C:''wamp''bin''mysql''mysql5.5.24''bin''mysqldump. --add-drop-table --host=" . $hostname . "--user=". $username ." --password=". $password." ".$dbname;

文件大小仍然不正确。我无法将下载的文件上传到phpMyAdmin。

结束更新

mysqldump需要转储到一个文件中,否则它只会以文本形式返回结果。

通常这是通过重定向到一个文件来完成的:

mysqldump --... > dump.sql