false中的含义是什么... if($ var!== false)

时间:2014-09-11 12:47:09

标签: php variables if-statement exec var

举个例子,如果启用了php exec,我会运行这个命令:/etc/init.d/mysql restart或者我需要将!== false设置为!== true吗?

$var = exec('/etc/init.d/mysql restart');

if ($var !== false) {
   echo "php exec is enabled";
}

基本上我要做的是,如果在服务器上启用此功能,则从php重启mysql

$var = exec('/etc/init.d/mysql restart');

if ($var !== false) {
   exec('/etc/init.d/mysql restart');
   echo "php exec is enabled and restart mysql";
}

1 个答案:

答案 0 :(得分:2)

如何检查功能会给你带来错误

$var = exec(); // need to pass an argument

检查功能是否存在尝试

if(function_exists('exec')) {
    echo "php exec is enabled";
}

另外根据更新,您需要将retrun参数传递给函数以检查返回值

exec('/etc/init.d/mysql restart', $output, $return);
// Return will return non-zero upon an error
if (!$return) {
   echo "php exec is enabled";
}

有关详情: - http://in1.php.net/manual/en/function.exec.php