Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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 Prepared语句fetch行不返回任何内容_Php_Mysql_Prepared Statement_Fetch - Fatal编程技术网

Php Prepared语句fetch行不返回任何内容

Php Prepared语句fetch行不返回任何内容,php,mysql,prepared-statement,fetch,Php,Mysql,Prepared Statement,Fetch,我想获取此行并将其保存到$notescheck中,但当我尝试执行此操作时,$notescheck在我想要回显时为空,并且没有错误。对于未准备好的报表,它可以正常工作。 代码: 对于未准备好的声明,它将如下所示: if($user_ok == true) { $sql = "SELECT notescheck FROM users WHERE username='$log_username' LIMIT 1"; $query = mysqli_query($conn, $sql)

我想获取此行并将其保存到
$notescheck
中,但当我尝试执行此操作时,
$notescheck
在我想要回显时为空,并且没有错误。对于未准备好的报表,它可以正常工作。

代码:

对于未准备好的声明,它将如下所示:

 if($user_ok == true) {
    $sql = "SELECT notescheck FROM users WHERE username='$log_username' LIMIT 1";
    $query = mysqli_query($conn, $sql);
    $row = mysqli_fetch_row($query);
    $notescheck = $row[0];
    mysqli_close($conn);
}
if($user_ok == true) {
        $sql = "SELECT notescheck FROM users WHERE username=? LIMIT 1";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("s",$log_username);
        $stmt->execute();
        $stmt->bind_result($notescheck);
        $stmt->store_result()
        while($stmt->fetch()){
           echo $notescheck;
        }
        $stmt->close();
    }
这不是fetch()处理预处理语句的方式,您并没有像想象中那样获取数组。您还需要将select的结果绑定到变量中,然后使用这些变量来显示。如果有多条记录,则使用
while($stmt->fetch){echo$notescheck}

if($user_ok == true) {
    $sql = "SELECT notescheck FROM users WHERE username=? LIMIT 1";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("s",$log_username);
    $stmt->execute();
    $stmt->bind_result($notescheck);
    $stmt->fetch();
    $stmt->close();
}
echo $notescheck;
您应该阅读以下内容:

多条与username=x匹配的记录如下所示:

 if($user_ok == true) {
    $sql = "SELECT notescheck FROM users WHERE username='$log_username' LIMIT 1";
    $query = mysqli_query($conn, $sql);
    $row = mysqli_fetch_row($query);
    $notescheck = $row[0];
    mysqli_close($conn);
}
if($user_ok == true) {
        $sql = "SELECT notescheck FROM users WHERE username=? LIMIT 1";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("s",$log_username);
        $stmt->execute();
        $stmt->bind_result($notescheck);
        $stmt->store_result()
        while($stmt->fetch()){
           echo $notescheck;
        }
        $stmt->close();
    }