doupaimo8288 2016-10-15 09:45
浏览 65
已采纳

使用pdo php执行过程后,bindparam变量的值为零

I'm using bindParam to bind the return value of stored procedure once the statement is executed

But i'm getting zero , i've specified output variable of stored procedure as BIGINT

and i'm binding parameter like below

$sql = "{:retval = CALL sp_testProc()}";
$stmt->bindParam('retval', $proc_pass_val, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);

bindparam is taking Length of data type as last parameter, i'm passing 4 here, but it returns zero, don't know why

Could anybody help me on this

Thanks in Advance

  • 写回答

1条回答 默认 最新

  • dousi1994 2016-10-17 08:50
    关注

    This is what I've done to make it work, Hope this helps someone.

    Note: Procedure defined in MSSQL server

    Here I want email into a field inorder to get that in an array, you can omit this line select @myemail as student_email; and you can get the value of @myemail into $myemail

    My Procedure:

    Alter proc [dbo].[sp_test_success](
    @Id int=1,
    @myemail varchar(250)=null output
    )
    AS
    BEGIN
        select @myemail=rtrim(email) from Student where StudentId=@Id;  
        select @myemail as student_email;-- i put this to get myemail into array 
    END
    

    Code:

    $dbh = new PDO('sqlsrv:Server=Server;Database=database', 'UID', 'Pwd');
    $stmt = $dbh->prepare("{CALL sp_test_success(@Id=:Id,@myemail=:myemail)}");
    
    $Id = 4;
    $stmt->bindParam('Id', $Id, PDO::PARAM_INT); 
    $stmt->bindParam('myemail', $myemail, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 500); 
    $stmt->execute();
    $results = array();
    do {
        $rows= $stmt->fetch();// default fetch type PDO::FETCH_BOTH
        $results[]= $rows;
    } while ($stmt->nextRowset());
    
    echo "<pre>"; print_r($results);
    
    print "procedure returned $myemail
    "; exit;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀