$a = Yii::app()->db->createCommand('SELECT productID FROM Product WHERE productID=1')->queryScalar();
echo $a.'<br />';
$altsCmd = Yii::app()->db->createCommand('SELECT secondaryID, userID, type FROM AlternativeProducts WHERE primaryID=:productID ORDER BY dtAdded DESC LIMIT 0,:maxAlts');
echo 'productID='.$p->productID.'<br />';
die('testBeforeBind');
$altsCmd->bindParam(':productID', $p->productID, PDO::PARAM_INT);
die('testAfterBind');
It shows
Quote
testBeforeBind
If I comment it out, it shows blank page (not "testAfterBind" as expected).
At the same time, this code (in another method) works fine:
$sizesCmd = Yii::app()->db->createCommand('SELECT s.size
FROM Size s
INNER JOIN Stock st ON s.sizeID=st.sizeID
WHERE st.productID=:productID');
$sizesCmd->bindParam(':productID', $p->productID, PDO::PARAM_INT);
$sizes = $sizesCmd->queryColumn();
or
$coloursCmd = Yii::app()->db->createCommand('SELECT c.name colour, crp.secondaryID productID
FROM Colour c
INNER JOIN ColourRelatedProducts crp ON c.colourID=crp.colourID
WHERE crp.primaryID=:productID');
$coloursCmd->bindParam(':productID', $p->productID, PDO::PARAM_INT);
$colours = $coloursCmd->queryAll();
I've just expereimented some more and found out, that you're right - when I don't have params in LIMIT section, it works fine. But that's strange…
On the local PC I have:
$altsCmd = Yii::app()->db->createCommand('SELECT secondaryID, userID, type FROM AlternativeProducts WHERE primaryID=:productID ORDER BY dtAdded DESC LIMIT 0,:maxAlts');
$altsCmd->bindParam(':productID', $p->productID, PDO::PARAM_INT);
$altsCmd->bindParam(':maxAlts', Yii::app()->params['product']['maxAlts'], PDO::PARAM_INT);
$alts = $altsCmd->queryAll();
and it's fine. On the remote one only this works:
$altsCmd = Yii::app()->db->createCommand('SELECT secondaryID, userID, type FROM AlternativeProducts WHERE primaryID=:productID ORDER BY dtAdded DESC LIMIT 0,'.Yii::app()->params['product']['maxAlts']);
$altsCmd->bindParam(':productID', $p->productID, PDO::PARAM_INT);
$alts = $altsCmd->queryAll();
$altsCmd = Yii::app()->db->createCommand('SELECT secondaryID, userID, type FROM AlternativeProducts WHERE primaryID=:productID ORDER BY dtAdded DESC LIMIT 0,:maxAlts');
$altsCmd->bindValue(':productID', $p->productID, PDO::PARAM_INT);
$altsCmd->bindValue(':maxAlts', Yii::app()->params['product']['maxAlts'], PDO::PARAM_INT);
$alts = $altsCmd->queryAll();
BindParam is special because it uses variable reference. The 'productID' is a property defined via __get(), and I guess that's why it may have trouble (this could be a PHP bug that was fixed in later versions).