Yii Framework Forum: how to bind stored procedure to yii2 - Yii Framework Forum

Jump to content

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

how to bind stored procedure to yii2 binding stored procedure with yii2 model and view

#1 User is offline   shruti Desai 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-November 17

Posted 06 November 2017 - 03:42 AM

this is my stored procedure plz any one help me to slove using mysql/mssql

ALTER PROCEDURE [dbo].[Emp]
-- Add the parameters for the stored procedure here

@empcode varchar(250)

AS
BEGIN


-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
declare @qry varchar(50);

--set @emp_id=1;
SET NOCOUNT ON;

-- Insert statements for procedure here
set @qry=(
SELECT empcode from acerp_employee_details
where empcode=@empcode);
return @qry
--execute Emp



END
this is my search part


$empcode='AI000064';
$query = Yii::$app->db->createCommand("CALL Emp(:empcode)")
->bindValue(':empcode' , $empcode)
0

#2 User is offline   shruti Desai 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 06-November 17

Posted 06 November 2017 - 03:44 AM

SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '@P1'.
The SQL being executed was: CALL Emp('AI000064')


I am getting this error
0

#3 User is offline   jkofsky 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 683
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 10 November 2017 - 02:20 PM

View Postshruti Desai, on 06 November 2017 - 03:44 AM, said:

SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '@P1'.
The SQL being executed was: CALL Emp('AI000064')


I am getting this error

Two things to try:
1. Change the single quotes ( ' ) on the value to double quotes ( " ).
or
2. There is a third param to bindValue() called dataType. There are predefined const for this, I believe you would need PDO::string, or something like that.
Do, or do not. There is no 'try.' Jedi Master Yoda
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