Error with CDbCommand "Invalid parameter number: no parameters were bound"


error occurs on executing INSERT query. Here is SQL code:

INSERT INTO Search VALUES(9, 10, 'Get started with Gmail Gmail is built on the idea that email can be intuitive, efficient, and\nuseful. And maybe even fun.\n\nLabels instead of folders\nLabels do the work of folders with an extra bonus: a conversation can have\nseveral labels, so you\'re not forced to choose one particular folder. Learn\nmore<>\n\n Archive instead of delete\nYou shouldn\'t ever have to throw things away. Archiving moves messages out\nof your inbox and into \"All Mail,\" so they don\'t clutter your inbox but\nremain searchable in case you ever need them again. Learn\nmore<>\n\n Conversation view\nGmail groups emails and their replies in your inbox, so you always see your\nmessages in the context of your conversation. Related messages are stacked\nneatly on top of each other, like a deck of cards. Learn\nmore<>\n\n Chat and video chat\nYou don\'t have to use another program -- chat is built right into Gmail. Learn\nmore<>\nYou can even talk face to face with voice and video chat. All you need is a\nwebcam and a small\ndownload<>that\ntakes seconds to install.\n\n Learn more<>about\ngetting started with Gmail.\n\nWelcome!\n\n- The Gmail Team\n\n ', 9)

And code which executes a command:

foreach ($this->attributes as $attribute) {

	    $index .= $this->getOwner()->{$attribute}.' ';


	$index = Yii::app()->db->quoteValue($index);

	if ($this->getOwner()->isNewRecord) {

	    $sql = "INSERT INTO Search VALUES($id, $type, $index, $companyId)";

	} else {

	    $sql = "UPDATE `Search` SET `index`= $index WHERE recordId = $id and recordType = $type and companyId = $companyId";


	$command  = Yii::app()->db->createCommand($sql);


It throws an exception: “CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound” but I haven’t specified any parameters. Why does it throw exception?


try to add {} like


for all of your variables between ""

and remove your `

or try with "INSERT INTO Search SET index = $index, etc…

The problem is not obvious in your case. You use DAO, so why don’t you use bindParam method ? It quotes any parameters instead you.