mysqli_stmt_fetch returns number

扶醉桌前 提交于 2019-12-11 05:08:09

问题


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:


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.



来源:https://stackoverflow.com/questions/20155786/mysqli-stmt-fetch-returns-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!