我想使用代码在本地主机上备份一个表。
$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = '';
$dbname = 'snapmall';
$dbtable = 'tb_translation';
$dbpath = 'D:test/new/';
//mysqldump -u root -p snapmall ps_translation > D:/test/new/ps_translation.sql
$command = "mysqldump -u $dbuser -p $dbpass $dbname $dbtable > ".$dbpath.$dbtable.".sql";
shell_exec($command);
我在 xampp 的 shell 上有测试命令,它工作正常,但是当我通过命令 shell_exec() 运行它时,结果文件是空的。
最佳答案
试试这个,添加 2>&1 以获取命令的输出:
$output = shell_exec($command." 2>&1");
然后在这里张贴。
你需要能够通过之前调用xamp来执行你的命令,因为你的exec访问的是bash,而不是xampp,所以,换句话说,你的exec必须可以访问基本命令集,配置你的PATH多变的。
关于php - 在 xampp 错误上通过 php 执行 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45551578/