SELECT statement with fetch_array in mysqli prepared statements

后端 未结 2 1881
既然无缘
既然无缘 2020-11-30 13:36

I always find it difficult to write MySQLi prepared statements, because many functions work differently than in the old way. Right now I am facing a problem regarding

相关标签:
2条回答
  • 2020-11-30 13:55

    you are trying to fetch the results by

    $result = $stmt->execute();
    

    which is not the case. as execute will return you only a boolean value.

    do it like.

    $stmt = $db->prepare("SELECT category_id FROM post_items Where user_id = ?");
    $stmt->bind_param('i', $userid);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
            //result is in row
    }
    
    0 讨论(0)
  • 2020-11-30 14:00

    replace this:

        $result = $stmt->execute();
        while ($row = $result->fetch_array()) {
    

    by this

      $stmt->bind_result($category_id);
    
      while($stmt->fetch()){
           $myArray=$category_id;
      }
    
    0 讨论(0)
提交回复
热议问题