Fatal error: Call to undefined method mysqli_stmt::get_result()

rks*_*ksh 3 php mysql mysqli

My following php MYSQLi is not working, PHP version 5.9

    $query = $conn->prepare("SELECT * FROM users WHERE token= ? LIMIT 1");
    $query->bind_param('s',$cvalue);
    $query->execute();
    $result = $query->get_result();
    $row = $result->fetch_assoc();
Run Code Online (Sandbox Code Playgroud)

It's giving me the following error:

Fatal error: Call to undefined method mysqli_stmt::get_result()

Where is the error? How can I fix it? Thanks

Fun*_*ner 5

评论太长了。

尝试这个:

if($statement=$conn->prepare("SELECT * FROM users WHERE token= ? LIMIT 1")){

     $statement-> bind_param('s',$cvalue);

     // Execute
     $statement-> execute();

     // Bind results
     $statement-> bind_result($token);

     // Fetch value
     while ( $statement-> fetch() ) {
          echo $token . "<br>";
     }

     // Close statement
     $statement-> close();
}

// Close entire connection
$conn-> close();
Run Code Online (Sandbox Code Playgroud)

现在,如果while ( $statement-> fetch() )它不像您想要的那样工作,请尝试用while ( $statement-> fetch_assoc() )您现在拥有的方式替换它。

  • 注意:如果这对您不起作用,我将简单地删除答案。

脚注:

火箭在核生化事故的注释说,我引用:它需要两个PHP 5.3+的mysqlnd驱动程序。

因此,请确保已安装驱动程序。