使用pdo_sqlsrv执行存储过程 [英] Executing a Stored Procedure with pdo_sqlsrv

查看:80
本文介绍了使用pdo_sqlsrv执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在sql server 2008上用php5.3/pdo_sqlsrv执行存储过程.

I'm trying to figure out how do execute a stored procedure with php5.3/pdo_sqlsrv on sql server 2008.

我找到了以下代码:

$sql = new PDO( "sqlsrv:server=$server;Database = $database", $user, $password);
$query = "{? = CALL sp_Login(?, ?)}"; 
$stmt = $sql->prepare( $query ); 
$returnVariable = 0;
$inputVariable1 = 'input1';
$inputVariable2 = 'input2';
$stmt->bindParam(1,$returnVariable,PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,100);
$stmt->bindParam(2,$inputVariable1,PDO::PARAM_STR);
$stmt->bindParam(3,$inputVariable2,PDO::PARAM_STR);
$stmt->execute();
echo "Return value: ".$returnVariable;

存储过程有两个输入和一个输出参数,但是似乎它什么也不返回,返回值仍然为0.

the stored procedure has two input and one output paramter, but it seems it returns nothing, return value is still 0..

我可以运行选择/插入查询,所以它不是连接.

I can run select/insert queries, so it's not the connection.

是否有关于pdo_sqlsrv存储过程的良好文档?

Is there any good documentation about stored procedures with pdo_sqlsrv?

谢谢!

推荐答案

经过一天的搜索,我发现了一种方法来调用sp ... 问题是存储过程正在运行插入查询,我不得不调用 nextRowset()获取返回值

after a day of search i found a way of calling the sp... the problem was that the stored procedure was running a insert query and i had to call nextRowset() to get the return value

http://social. msdn.microsoft.com/Forums/zh-CN/sqldriverforphp/thread/55f21fc5-dbc0-4fe4-a4ae-f15905a4293a

$sql = new PDO( "sqlsrv:server=$server;Database = $database", $user, $password);

$input1 = "input1";
$input2 = "input2";
$return_value = -1;

$proc = '{? = CALL sp_Name (?, ?) }';
$stmt = $sql->prepare( $proc );
$stmt->bindParam(1,$return_value ,PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,4);
$stmt->bindParam(2,$input1,PDO::PARAM_STR);
$stmt->bindParam(3,$input2,PDO::PARAM_STR);

$stmt->nextRowset(); //skip INSERT result

$result = $stmt->fetch(PDO::FETCH_ASSOC);
/* Display the value of the output parameter  */
echo "Return value: ".$return_value.'<br>';

这篇关于使用pdo_sqlsrv执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆