我有以下代码,print_r返回Array()而不是我期望的数据。
$stmt = $db->prepare('SELECT sc.classID, sc.longDesc, si.specItemName, si.itemCost, scp.shipUpgradeCost, scp.shipUpgradePrice FROM shipclasses sc JOIN specialitems si ON sc.specItemID=si.specItemID JOIN shipcostingpricing scp ON sc.classID=scp.classID WHERE sc.classID>=:currentclass AND sc.classID<=:upgradeclass');
$stmt->bindParam(':currentclass', $currentclass, PDO::PARAM_INT);
$stmt->bindParam(':upgradeclass', $upgradeclass, PDO::PARAM_INT);
$upgradeInfo = $stmt->fetchALL(PDO::FETCH_OBJ);
当我从sql运行此查询时:
SELECT sc.classID, sc.longDesc, si.specItemName, si.itemCost, scp.shipUpgradeCost, scp.shipUpgradePrice FROM shipclasses sc JOIN specialitems si ON sc.specItemID=si.specItemID JOIN shipcostingpricing scp ON sc.classID=scp.classID WHERE sc.classID>=2 AND sc.classID<=5;
它返回我希望它返回的数据。我认为PDO存在&gt; =和&lt; =的问题。有人可以帮我吗?
答案 0 :(得分:0)
抱歉,我忘了在行$stmt->execute();
$upgradeInfo = $stmt->fetchALL(PDO::FETCH_OBJ);
答案 1 :(得分:0)
而不是sc.classID&gt; =:currentclass AND sc.classID&lt; =:upgradeclass你可以使用
sc.classID between (:currentclass AND :upgradeclass)