【发布时间】:2011-03-23 00:43:57
【问题描述】:
我似乎无法让这个或类似的语句与准备好的查询一起工作,代码在下面工作得很好:
$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 = '?' 时,它会给我一个错误,即参数数量不匹配。这是行不通的语句。
$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();
有人可以帮忙吗?
【问题讨论】:
-
我认为应该是
t.tag_name = ?,而不是t.tag_name = '?'。 -
我认为您不需要在 ? 周围加上单引号。
标签: php mysqli prepared-statement