内部连接将无法与php中的mysqli准备语句一起使用 [英] inner join wont work with mysqli prepared statement in php

查看:52
本文介绍了内部连接将无法与php中的mysqli准备语句一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使该语句或类似语句与准备好的查询一起使用,该代码在下面的工作正常:

I can't seem to get this statement or statements alike to work with prepared queries, the code works just fine below:

$DBH = getDBH();
    $stmt = $DBH->prepare("SELECT a.id, a.title, a.photo FROM tag t INNER JOIN tag_reference atx ON t.tag_id = atx.tag_id
        INNER JOIN articles a
            ON atx.article_id = a.id
    WHERE t.tag_name = 'example'");
    $stmt->execute();
    $stmt->bind_result($id,$title,$photo);
    $stmt->fetch();

但是当我更改t.tag_name = '?'时,它给我一个错误,指出参数数量不匹配.这是行不通的语句.

but when I change t.tag_name = '?' it gives me an error that the amount of parameters do not match. This is the statement that does not work.

$DBH = getDBH();
    $stmt = $DBH->prepare("SELECT a.id, a.title, a.photo FROM tag t INNER JOIN tag_reference atx ON t.tag_id = atx.tag_id
        INNER JOIN articles a
            ON atx.article_id = a.id
    WHERE t.tag_name = '?'");
        $stmt->bind_param('s',$example);
    $stmt->execute();
    $stmt->bind_result($id,$title,$photo);
    $stmt->fetch();

任何人都可以帮忙吗?

推荐答案

如果用单引号引起来,占位符?不起作用.在这种情况下,SQL标记器会将其捕获为文字字符串.

The placeholder ? does not work if enclosed in single quotes. In this case the SQL tokenizer will catch it as literal string.

将其更改为:

     WHERE t.tag_name = ? ");

这篇关于内部连接将无法与php中的mysqli准备语句一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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