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 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站