Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过php选择的表备份数据库mysql表_Php_Mysql_Database_Backup - Fatal编程技术网

如何通过php选择的表备份数据库mysql表

如何通过php选择的表备份数据库mysql表,php,mysql,database,backup,Php,Mysql,Database,Backup,我想使用mysqldump、、、从数据库mysql和php逐表备份 使用复选框在列表上显示我的表格 如果表列表选中全部,则我的所有表备份 如果表1、表2、表3等的列表选中了“我的表已选中备份” 这是我的代码: <?php include "config/conn.php"; echo "<h1>Database name: ".$db."</h1></br>"; echo "list of Tabel:"; $query

我想使用mysqldump、、、从数据库mysql和php逐表备份

使用复选框在列表上显示我的表格

如果表列表选中全部,则我的所有表备份

如果表1、表2、表3等的列表选中了“我的表已选中备份”

这是我的代码:

<?php
    include "config/conn.php";
    echo "<h1>Database name: ".$db."</h1></br>";
    echo "list of Tabel:";
    $query = "SHOW TABLES";
    $hasil = mysql_query($query);

    echo "<form method='post' action='db/backupAction.php'>";
    echo "<table>";
    while ($data = mysql_fetch_row($hasil))
    {
       echo "<tr><td><input type='checkbox' name='tabel[]' value='".$data[0]."'></td><td>".$data[0]."</td></tr>";
    }
    echo "</table><br>";
    echo "<input type='submit' name='submit' value='Backup Data' class='btn'>";
    echo "</form>";

?>

我的结果文件.sql为空


为什么?

上述代码存在两个问题。首先,您应该确保在mysqldump命令中分离用户

  mysqldump --user=".$user."
在创建ListTable字符串的for-each循环中,没有在末尾添加空格。此外,不需要使用look来连接字符串,您可以

其次,在开始回显要备份的所有表名之前,应该添加--tables参数

最后,在PHP中,“\”是一个特殊的转义字符。您要么需要使用两个,要么将命令用单引号括起来。您不需要转义“>”字符

基本上,该命令如下所示:

$listTabel = '';
if (is_array($tabel))
    $listTabel = implode(" ", $tabel);

$executable = 'C:\xampp\Mysql\bin\mysqldump ';
$command = $executable;
if (isset($user) && $user != '')
    $command .= '--user='.$user.' ';
if (isset($pass) && $pass != '')
    $command .= '--password='.$pass.' ';

$command .= $db

if (isset($listTabel) && $listTabel != '')
    $command .=' --tables'.$listTabel;

$command .= ' > '.$db.'.sql';

您能回显
$command
吗?当您从命令行运行它时,它是否工作?
“\>”
在您的$command中似乎无效。请回送它。我的回送结果是“array”,如果我的输入名称是change name='tabel',我的结果是table name,但结果是相同的null或blanksame,我的结果是null或blanksame请告诉我们回送$command是什么;出口$command=…我使用内爆进行更改之后的输出我的结果是内爆()[]:传入的参数无效……$command我是echo然后结果是C:\xampp\Mysql\bin\mysqldump--user=root--password=myDb--tables>myDb.sqlOK,看起来$tabel没有正确填充。请在$tabel=$\u POST['tabel']下方的$tabel上进行打印/var转储;让我们知道它的输出。
$listTabel = '';
if (is_array($tabel))
    $listTabel = implode(" ", $tabel);

$executable = 'C:\xampp\Mysql\bin\mysqldump ';
$command = $executable;
if (isset($user) && $user != '')
    $command .= '--user='.$user.' ';
if (isset($pass) && $pass != '')
    $command .= '--password='.$pass.' ';

$command .= $db

if (isset($listTabel) && $listTabel != '')
    $command .=' --tables'.$listTabel;

$command .= ' > '.$db.'.sql';