简体   繁体   English

如何将参数从php传递到存储过程

[英]How to pass parameter into stored proceedure from php

I have a stored Proceedure 'spGetOrderByID' in the sql server. 我在sql服务器中存储了一个过程'spGetOrderByID'

Which gives a record according the given order id. 它根据给定的订单ID给出一条记录。

And the stored proceedure is working fine , while i trying in the sql server. 和存储的过程工作正常,而我在SQL Server中尝试。

This is the php code iam using 这是IAM使用的PHP代码

$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? 1:让我知道痛苦的结果将在$ orderId中,对不对?

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 2:我是否需要在php中设置任何新设置以使存储过程正常工作。但是已经可以成功连接ms sql服务器了

3: Now i getting Warning: mssql_execute(): stored procedure execution failed 3:现在我得到警告:mssql_execute():存储过程执行失败

Please advise me 请建议我

You use the msql_bind command. 您使用msql_bind命令。 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. 其中varInput对应于在存储过程中声明的输入var。 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. 您可以通过执行多个msql_bind命令,将不同的PHP var绑定到不同的存储过程var,来分配多个输入和输出var。

For more info and examples, visit http://php.net/manual/en/function.mssql-bind.php 有关更多信息和示例,请访问http://php.net/manual/en/function.mssql-bind.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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