Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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 从数据库中选择no item返回1,为什么?_Php_Mysql - Fatal编程技术网

Php 从数据库中选择no item返回1,为什么?

Php 从数据库中选择no item返回1,为什么?,php,mysql,Php,Mysql,你好,我有三个小问题。。。我在php中有以下关于mysql的查询。。。 它在选择后为我提供值0,即使没有bla=$bla-它应该为我提供值,为什么它为我提供0 第二个问题:结果是1-为什么选择成功,即使没有bla=$bla 第三个问题:由于WHERE条件未成功而未选择任何项目,我如何知道选择未成功 $stmt= $this->conn->prepare("SELECT id FROM column WHERE bla = ?"); $stmt-> bind_param(

你好,我有三个小问题。。。我在php中有以下关于mysql的查询。。。 它在选择后为我提供值0,即使没有bla=$bla-它应该为我提供值,为什么它为我提供0

第二个问题:结果是1-为什么选择成功,即使没有bla=$bla

第三个问题:由于WHERE条件未成功而未选择任何项目,我如何知道选择未成功

$stmt= $this->conn->prepare("SELECT id FROM column WHERE bla = ?");
    $stmt-> bind_param("s", $bla);

        $result = $stmt->execute();
        $result = $stmt -> bind_result($id);

        echo $result;

在你的代码中
$result
是查询执行的结果。它不是SQL语句中的数据


execute
返回一个布尔值。请参阅:

echo$id-非
$result
!$id是否包含成功的结果?所以$id=1,成功了。如果为0,则不是?啊,您想知道查询是成功还是失败?然后你需要检查
$stmt->execute()
,不一定是
绑定结果()
是的,我试过了,但是$stmt-execte()给出了TRUE-即使没有任何选择^^^它是否返回TRUE,即使它没有选择任何值?是的$stmt->num_rows>0做了^^好的。。。我不知道它给了我积极的结果,即使它没有选择任何项目,因为没有与where子句对应的项目:)