这是我在预备语句中的第一次尝试,而不是返回单个文本元素,而是我得到一个数字。数字1
具体。有人说它与计算记录有关,但我不知道如何关闭它。
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);
}
答案 0 :(得分:1)
应该是:
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指示的变量中。