简体   繁体   English

PHP系统返回127错误码

[英]PHP System return 127 error code

I've tried to backup my database with the following php code on mac Sierra:我尝试在 mac Sierra 上使用以下 php 代码备份我的数据库:

$command = "mysqldump --opt -u root -proot si_clinic_pos > clinic.sql";
system($command, $output);

if($output != 0) {
  echo $output;
}else {
  echo 'Database saved';
}

The output is "127", but if I tried to execute the "mysqldump --opt -u root -proot si_clinic_pos > clinic.sql" inside terminal, it's working fine.输出是“127”,但如果我尝试在终端内执行“mysqldump --opt -u root -proot si_clinic_pos > Clinic.sql”,它工作正常。

what's wrong with it, could you please help me?有什么问题,你能帮帮我吗?

The solution to the problem is to specify the full path to the executable file you want to run.该问题的解决方案是指定要运行的可执行文件的完整路径。

So, in this specific case, instead of:因此,在这种特定情况下,而不是:

$command = "mysqldump ...";

you need to have:你需要:

$command = "/usr/bin/mysqldump ...";

/bin/sh 无法执行,退出状态将是执行 exit(127) 的命令。我建议您以 root 用户身份运行 PHP 程序。

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

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