简体   繁体   中英

How to pass parameter into stored proceedure from php

I have a stored Proceedure 'spGetOrderByID' in the sql server.

Which gives a record according the given order id.

And the stored proceedure is working fine , while i trying in the sql server.

This is the php code iam using

$this->_connectionString = mssql_connect($host, $username, $password) or die("can't connect to server1");
$this->_dbName ='databaseName";
$selectDB = mssql_select_db($this->_dbName, $this->_connectionString ) or die('Databse error'); 

$sp = mssql_init('spGetOrderByID',  $this->_connectionString);
$orderId =824;

mssql_bind($sp, "@orderID", $orderId, SQLINT1, false, false);
mssql_execute($sp,$this->_dbName);

echo $orderId;

1: let me know the result of the sored proceedure will be in $orderId, right?

2: Do i need to set a any new setting in php, for the stored proceedure to working.But already i can connect the ms sql server successfully

3: Now i getting Warning: mssql_execute(): stored procedure execution failed

Please advise me

You use the msql_bind command. As such:

$sp = mssql_init('stored_p', $db);
mssql_bind($sp, "@varInput", $input, VARCHAR, false, false);
mssql_execute($sp,$db);

Where varInput corresponds to an input var declared in the stored procedure. Output vars can be assigned in a similar fashion. You can assign multiple input and output vars by making multiple msql_bind commands, binding different PHP vars to different stored procedure vars.

For more info and examples, visit http://php.net/manual/en/function.mssql-bind.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM