當我試圖在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