gpt4 book ai didi

php - Bind Param 不起作用是怎么回事?

转载 作者:行者123 更新时间:2023-11-29 15:44:18 25 4
gpt4 key购买 nike

我正在另一台服务器上执行存储过程。我希望能够将我的参数/变量传递给该存储过程。但是,我的代码没有达到这一点,因为它在 bindParam 部分失败。

我在线查看了bindParam 和不同的示例。我尝试过可能不同的事情和变化,但似乎没有任何效果。我认为这一定是某个地方的语法错误,但代码在编辑器中 check out 。

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();
}

我想要的是能够将变量传递给存储过程...

最佳答案

问题1

方法bindParam需要一个变量作为第二个参数。您正在使用字符串。

如果您不想使用变量,您应该使用 bindValue方法代替。

所以要么是:

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

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

问题2

PDO::PARAM_NUM 不是有效常量。请改用 PDO::PARAM_INT

关于php - Bind Param 不起作用是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57246046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com