dongzantai7570 2019-07-29 00:47 采纳率: 0%
浏览 64

Bind Param不工作有什么不对?

I am executing a Stored Procedure on another server. I want to be able to pass my paramaters/variables to that Stored Procedure. However, my code stops short of that as it fails on the bindParam part.

I have looked at bindParam online and at different examples. I have tried may different things and variations but nothing seems to work. I assume it must be a syntax error someplace but code checks out in editor.

try {


    $conn = new PDO("sqlsrv:Server=$server;Database=$database", $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

    if($conn){

    echo "Connection is good.... <br />";
    $sql = 'CALL web.WebImportWoRequestDirect (:WebREQUESTEDBY, :WebSTARTDATE, :WebFINISHDATE, :WebTASKDESC, :WebSITEID, :WebLOCATION, :WebPRIORITY, :WebESTDURATION, :WebPHONE, :WebEXT, :WebTEXTS)';

    echo "Stored Procedure has been called....<br />";

    // prepare for execution of the stored procedure
    $stmt = $conn->prepare($sql);
    echo "Preparing SQL Statement... <br />";

    // pass value to the command
    $stmt->bindParam(':WebREQUESTEDBY', 'WEBUSER00001', PDO::PARAM_STR);
    $stmt->bindParam(':WebSTARTDATE', '06-28-2019', PDO::PARAM_STR);
    $stmt->bindParam(':WebFINISHDATE',  '06-29-2019', PDO::PARAM_STR);
    $stmt->bindParam(':WebTASKDESC',  'Title Here...', PDO::PARAM_STR);
    $stmt->bindParam(':WebSITEID',  'UMONCTON', PDO::PARAM_STR);
    $stmt->bindParam(':WebLOCATION',  'Some Place', PDO::PARAM_STR);
    $stmt->bindParam(':WebPRIORITY',  '2', PDO::PARAM_NUM);
    $stmt->bindParam(':WebESTDURATION',  '', PDO::PARAM_NUM);
    $stmt->bindParam(':WebPHONE',  '555-555-5555', PDO::PARAM_STR);
    $stmt->bindParam(':WebEXT', 'MCH1', PDO::PARAM_STR);
    $stmt->bindParam(':WebTEXTS',  'Massive text here...', PDO::PARAM_LOB);

    echo "CHECK - pass value to the command...<br />";

    //Execute the stored procedure...
    $stmt->execute();

    echo "Executed Stored Procedure....<br />";

    #$conn = null;
    }
    echo "Well... ask Gif if it worked...";

} catch (PDOException $e) {
            echo "There is some problem in connection: <br />" . $e->getMessage();
}

What I want is to be able to pass the variables to the stored procedure...

  • 写回答

1条回答 默认 最新

  • duanjiao8871 2019-07-29 06:52
    关注

    Problem 1

    The method bindParam requires a variable as the second parameter. You are using strings.

    If you don't want to use variable you should use the bindValue method instead.

    So it's either:

    $stmt->bindValue(':WebREQUESTEDBY', 'WEBUSER00001', PDO::PARAM_STR);
    

    or

    $webuser = 'WEBUSER00001';
    $stmt->bindParam(':WebREQUESTEDBY', $webuser, PDO::PARAM_STR);
    

    Problem 2

    PDO::PARAM_NUM is not a valid constant. Use PDO::PARAM_INT instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗