Hi, I have serious problem to use bindParam/Value together with SELECT statments using query(), it works fine with INSERT using execute().
Why is that? ![]()
Hi, I have serious problem to use bindParam/Value together with SELECT statments using query(), it works fine with INSERT using execute().
Why is that? ![]()
What is the problem? More details on how to reproduce it?
This one works perfect:
$sql = "INSERT INTO BibleVerses_BibleVerseIndex(BibleVersesID, BibleVerseIndexID) VALUES(:BibleVersesID, :BibleVerseIndexID)";
foreach($bverse as $v)
$verses["{$v['book']} {$v['chapter']} {$v['verse']}"] = $v['id'];
foreach($bvindex as $v)
$verseindex["{$v['book']} {$v['chapter']} {$v['verse']}"] = $v['id'];
foreach($verses as $key => $value)
if(array_key_exists($key, $verseindex))
{
$bverse = $db->createCommand($sql);
$bverse->bindParam(":BibleVersesID",$value,PDO::PARAM_INT);
$bverse->bindParam(":BibleVerseIndexID",$verseindex[$key],PDO::PARAM_INT);
$bverse->execute();
}
This doesn't work:
$sql = <<<EOD
SELECT bvi.Book AS book, bvi.Chapter AS chapter, bvi.Verse AS verse, bv.Text AS text
FROM BibleVerseIndex bvi
JOIN (
BibleVerses_BibleVerseIndex bvbvi,
BibleVerses bv,
BibleTranslations bt)
ON(
bvi.BibleVerseIndexID = bvbvi.BibleVerseIndexID AND
bvbvi.BibleVersesID = bv.BibleVersesID AND
bv.BibleTranslationsID = bt.BibleTranslationsID)
WHERE
bt.Translation = ':translation' AND
bvi.Book = ':book'
EOD;
$command = Yii::app()->db->createCommand($sql);
$command->bindParam(':translation', $this->_translation, PDO::PARAM_STR);
$command->bindParam(':book', $book, PDO::PARAM_STR);
return $command->query();
You should remove those quotes around the parameter placeholders.
Tada!!!
Works, thanks
I meet the same problem, thanks, it works well now.