duanmiaosi0150 2013-09-16 12:03
浏览 48
已采纳

如何使用mysqli绑定此1变量?

Ok, so I have been at this for hours now, and no matter what i do, it just doesn't work. I've read pages of documentation and even tried verbatim by examples, and still doesn't work:

$db = mysqli_connect($db_server, $db_user, $db_passwd, $db_name);

if (mysqli_connect_errno())
{
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}

$db_query = "SELECT ca.id_article, ca.title, ca.body, ca.id_tag, ca.visible, ct.title AS tag_title
            FROM cdfi_articles AS ca
            INNER JOIN cdfi_tags AS ct ON(ct.id_tag = ca.id_tag)
            WHERE ca.id_article = ?
            LIMIT 1";
;
if ($stmt = mysqli_prepare($db, $db_query)) {
    mysqli_stmt_bind_param($stmt, "i", $_REQUEST['article']);

    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $return);
    mysqli_stmt_fetch($stmt);

    var_dump($return);

}

mysqli_close($db);

The following error occurs and I don't know how to fix it at all:

Warning: mysqli_stmt_bind_result() [function.mysqli-stmt-bind-result]: Number of bind variables doesn't match number of fields in prepared statement in ... filepath on line {line number}

bind variables don't match? I am only using 1 variable, and only 1 question mark within the query, what gives??

var_dump($return) returns NULL value

How can I fix this? I just want to get that 1 row returned within the $return variable so that I can do something with it, arggg!

  • 写回答

1条回答 默认 最新

  • dqwh1202 2013-09-16 12:22
    关注

    You are selecting 6 columns but you are only binding $return in mysqli_stmt_bind_result($stmt, $return);

    Try

    mysqli_stmt_bind_result($stmt, $artid, $title, $body, $tagid, $vis, $tagtitle );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类