gpt4 book ai didi

php - Mysql_stmt::bind_result()

转载 作者:行者123 更新时间:2023-11-30 00:12:42 25 4
gpt4 key购买 nike

我有以下 mysql 查询正在我的 php 脚本中执行:

$qr = "Select p.productID,p.productDesc,p.productQty,";
$qr .= "p.productPr,p.type,p.gender,p.date From";
$qr .= " products AS p";
$qr .= " INNER JOIN(Select c.productID, GROUP_CONCAT(";
$qr .= "DISTINCT c.availCol) AS color_list FROM";
$qr .= " availColors AS c GROUP BY c.productID) AS colors";
$qr .= " ON p.productID = colors.productID":
$qr .= " INNER JOIN(SELECT s.productID, GROUP_CONCAT";
$qr .= "(s.availSizes) AS size_list FROM availSizes AS s";
$qr .= " GROUP BY s.productID) AS sizes ON p.productID";
$qr .= " = sizes.productID";
$qr .= " INNER JOIN(SELECT avp.productID, avp.productImg";
$qr .= " FROM availImg AS avp ORDER BY avp.productID";
$qr .= " LIMIT 3) AS images ON images.productID = ";
$qr .= " p.productID";
$qr .= " WHERE p.productID = ?";
$qr .= " GROUP BY p.productID";

$stm = $mysqli->prepare($qr);
$stm->bind_param('s',$id);
$stm->execute();
$stm->store_result();

If($stm->num_rows == 1){
$stm->bind_result($pid,$desc,$qty,$pr,$type,$gender,
$date,$colID,$color,$sizeID,$sizes,$imgID,$imgUrl);

$stm->fetch();
......
}

当我执行脚本时,我收到一条错误消息: Mysqli_stmt::bind_result():绑定(bind)变量的数量不 匹配准备好的语句中的字段数...

我明白这个错误的含义,但我已经根据 SELECTed 列的数量重新检查并重新计算了 bind_result() 中的绑定(bind)变量的数量,我只是无法弄清楚出了什么问题。我不知道 PHP 如何评估从 mysql 子查询返回的值。有人能提供这方面的帮助吗?我一整天都在做这个!感谢您的帮助!

最佳答案

$qr = "
Select
p.productID,
p.productDesc,
p.productQty,
p.productPr,
p.type,
p.gender,
p.date
From
products AS p
INNER JOIN(
Select
c.productID,
GROUP_CONCAT(DISTINCT c.availCol) AS color_list
FROM
availColors AS c GROUP BY c.productID) AS colors
ON
p.productID = colors.productID
INNER JOIN(
SELECT
s.productID,
GROUP_CONCAT(s.availSizes) AS size_list
FROM
availSizes AS s
GROUP BY
s.productID
) AS sizes
ON
p.productID = sizes.productID
INNER JOIN(
SELECT
avp.productID,
avp.productImg
FROM
availImg AS avp
ORDER BY
avp.productID
LIMIT
3) AS images
ON
images.productID = p.productID
WHERE
p.productID = ?
GROUP BY
p.productID";

尝试像这样格式化您的查询,多行字符串在 PHP 中完全没问题,并且几乎不可能理解它逐行连接的意义。如果我没说错的话,你至少缺少一个右括号,第一个内连接左括号没有关闭。

关于php - Mysql_stmt::bind_result(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23918988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com