Passing Sp Parameter

Hi,

While trying to call a sp with single argument using create command from model,it shows error like this.

"CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. The SQL statement executed was: CALL usp_search_employee(:criteria) ".The code is given below.


mymodel.php


public function search($searchKey)

{


	


	//query builder


	$data = Yii::app()->db->createCommand("CALL usp_search_employee(:criteria)")


	        ->queryAll(array(':criteria'=>$searchKey));		


			print_r($data);


	return $data ;


}

mycontroller.php


public function actionIndex()

{			


	$searchValue           = trim(CHttpRequest::getPost('txtName',''));


	$objSearch              = new SearchEmpDao();


	


	$findEmp                = $objSearch->search($searchValue);


	$this->render('ListEmp',array("list"=>$findEmp,));


}

Any ideas?

The first argument to queryAll() is $fetchAssociative, not the parameter array.

See here.

You probably want:




$data = Yii::app()->db->createCommand("CALL usp_search_employee(:criteria)")

    ->queryAll(true, array(':criteria'=>$searchKey));



Thanks.It worked.