简体   繁体   English

转储查询输出是php中的空zip文件

[英]Dump Query Output is Empty zip file in php

I am trying to get run dump Query using php, But is creating 0 byte zip file, and no db backup is create 我正在尝试使用php获取运行转储查询,但是创建了0字节的zip文件,并且没有创建数据库备份

****My code is here******* ****我的代码在这里*******

<?php
$dir = "path/to/file/";
$filename = "backup" . date("YmdHis") . ".sql.gz";

$db_host = "localhost";
$db_username = "root";
$db_password = "121";
$db_database = "wp_test";

$cmd = "mysqldump -h {$db_host} -u {$db_username} --password={$db_password} {$db_database} | gzip > {$dir}{$filename}";
exec($cmd);

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");

passthru("cat {$dir}{$filename}");
?>

You can use this https://github.com/ajeetku/php-utility-Scripts/blob/master/load.php 您可以使用此https://github.com/ajeetku/php-utility-Scripts/blob/master/load.php

you need to replace some basic values than you can dump your SQL DB 您需要替换一些基本值,而不是转储SQL DB

$filename = 'xxxxxx';
// MySQL host
$mysql_host = 'localhost';
// MySQL username
$mysql_username = 'xxxxxxx';
// MySQL password
$mysql_password = 'xxxxxxx';
// Database name

$mysql_database = 'xxxxxxx';

In your code, you are using php executable command 在您的代码中,您正在使用php可执行命令

In that file you can see here All table Codes will be written problematically. 在该文件中,您可以看到所有表格代码将被写入有问题。 It will be better for you. 对你来说会更好。 "BEST OF LUCK" “最好的运气”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM