douzhangli9563
douzhangli9563
2013-11-22 22:35

mysqli_stmt_fetch返回数字

已采纳

This is my first attempt at a prepared statement and instead of returning a single text element, I'm getting a number instead. The number 1 to be specific. Somebody said its got something to do with counting the records but I'm not sure how to turn it off.

function primary_include2($url_keyword)
  {
    $link = select_db();
    $query = "select file_path FROM primary_includes WHERE url_label=?";
    $stmt = mysqli_prepare($link, $query);
    mysqli_stmt_bind_param($stmt, 's', $url_keyword);

    if ($result = mysqli_stmt_execute($stmt)); 
      {
        mysqli_stmt_bind_result($stmt, $file_path);
        $path = mysqli_stmt_fetch($stmt);
        return $path;
        }
    mysqli_close($link);
  }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • drema2014 drema2014 8年前

    It should be:

    function primary_include2($url_keyword)
    {
        $link = select_db();
        $query = "select file_path FROM primary_includes WHERE url_label=?";
        $stmt = mysqli_prepare($link, $query);
        mysqli_stmt_bind_param($stmt, 's', $url_keyword);
    
        if ($result = mysqli_stmt_execute($stmt)); 
        {
            mysqli_stmt_bind_result($stmt, $file_path);
            mysqli_stmt_fetch($stmt);
            return $file_path;
        }
        mysqli_close($link);
    }
    

    because mysqli_stmt_fetch returns true/false if a record was retrieved or not. The actual values are stored in variables indicated to mysqli_stmt_bind_result.

    点赞 评论 复制链接分享

相关推荐