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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)