当我试图在PHP中执行一个函数时,MySQLi查询正在执行,但只返回值0,但查询在数据库上执行。MYSQLi返回0然而查询在数据库上执行
function get_delivery_cost($mysqli, $item_ids) {
$query = $mysqli->prepare("SELECT (max(item_single_cost) + sum(item_additional_cost)) AS total FROM item_delivery WHERE item_id IN (?) AND item_single_cost NOT IN (SELECT max(item_single_cost) FROM item_delivery WHERE item_id IN (?)) LIMIT 1");
$query->bind_param('ss', $item_ids, $item_ids);
$query->execute();
$query->store_result();
$query->bind_result($delivery_cost);
$query->fetch();
return $delivery_cost;
}
的$ ITEM_IDS样品是1,2,3,当相同的查询被直接跑的总列返回对数据库£3.30然而,库MySQLi函数返回0
运行在PHP该功能是:
<?
array_push($item_ids, $basket_item->item_id);
$ids = join(',', $item_ids);
$delivery_cost = get_delivery_cost($mysqli, $ids);
echo number_format($delivery_cost, 2);
?>
注意:你也应该叫'$查询 - >关闭()'大功告成了。 – GolezTrol 2014-09-20 10:46:39
由于您正在读取数据,因此对'$ query-> store_result();的调用似乎已过时。不过,应该不重要。 – GolezTrol 2014-09-20 10:51:08
您是否检查过任何结果值?例如,你是否检查'execute'和'fetch'是否返回了“false”以外的值? – GolezTrol 2014-09-20 10:52:36