mysqli_stmt_fetch返回数字 [英] mysqli_stmt_fetch returns number

查看:96
本文介绍了mysqli_stmt_fetch返回数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试准备好的语句,而不是返回单个文本元素,而是获取一个数字.具体数字1.有人说这与记录计数有关,但我不确定如何将其关闭.

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);
  }

推荐答案

应为:

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);
}

因为mysqli_stmt_fetch返回true/false,无论是否检索到一条记录.实际值存储在指示为mysqli_stmt_bind_result的变量中.

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.

这篇关于mysqli_stmt_fetch返回数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆