Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I bind a parameter in sqlsrv_prepare?

We have this stored procedure which created by the other guiys

    DECLARE @RC int
DECLARE @Number varchar(10)

-- TODO: Set parameter values here.

EXECUTE @RC = [dbo].[spWebGetPrice] 
   @Number
GO

My question is how can I bind a value on @Number using sqlsrv_prepare.

I am using this code but it says that the parameter is still not supplied

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$sql = sqlsrv_prepare($conn,"spWebGetPrice", ['@Number', 123456]);

>Solution :

Procedure arguments are separate from prepared query placeholders.

sqlsrv_prepare expects as its second argument a full string of SQL, with ? in place of data which will be supplied as separate parameters. This is easier to illustrate with a plain select query:

sqlsrv_prepare($conn, 'Select * From Users Where Username=?', [$username]);

To run a stored procedure, you need to do the same thing – write out the SQL with ? placeholders:

sqlsrv_prepare($conn, 'Exec spWebGetPrice @Number=?', [123456]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading