Yii Framework Forum: Passing Sp Parameter - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Passing Sp Parameter Rate Topic: -----

#1 User is offline   RKA 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 19-February 13

Posted 19 February 2013 - 06:23 AM

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?
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,511
  • Joined: 04-March 10
  • Location:UK

Posted 19 February 2013 - 07:27 AM

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));

0

#3 User is offline   RKA 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 19-February 13

Posted 20 February 2013 - 12:34 AM

View PostKeith, on 19 February 2013 - 07:27 AM, said:

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users