简体   繁体   English

mysqli_query返回false而不是value

[英]mysqli_query return false instead of value

I need some help 我需要协助

I want my script to run if the mysqli_query returns off I set value of id=1 to off 如果mysqli_query返回,我希望我的脚本运行我将id = 1的值设置为off

But my script does not run. 但是我的脚本无法运行。 But if i replace if off with false it works fine. 但是,如果我用false替换掉它就可以了。

What can be wrong ? 有什么问题吗?

 $query3=mysqli_query($con,"SELECT * FROM choice WHERE id=1");
 $query4=mysqli_fetch_array($query3);
 if ($query4['choice'] == off) {
    $output = shell_exec('sudo python test1.py');

Assuming this isn't a MySQL problem, try this: 假设这不是MySQL问题,请尝试以下操作:

 if (strcmp($query4['choice'], 'off') == 0) {
    $output = shell_exec('sudo python test1.py');
 }

Or even: 甚至:

 if ($query4['choice'] === 'off') {
    $output = shell_exec('sudo python test1.py');
 }

In the first example, we are comparing the string for equality, if zero is returned, there is no difference, meaning the strings are identical in every way. 在第一个示例中,我们比较字符串是否相等,如果返回零,则没有区别,这意味着字符串在各个方面都是相同的。

In the second example, we are checking for type with the triple equal sign === , so it will compare string to string properly as well. 在第二个示例中,我们正在检查带有三等号=== ,因此它也会正确比较字符串。

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

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