使用> =和< =时,PDO中的语法

时间:2015-06-07 01:59:49

标签: php mysql pdo

我有以下代码,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; =的问题。有人可以帮我吗?

2 个答案:

答案 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)