[英]Parameters with PDO for stored procedure
如何在PDO中使用2個參數調用SQL Server的存儲過程。
例如,在SQLServer的提示中:
EXEC測試'arg1','arg2'
帶有PDO的PHP的下一步是什么?
預先感謝您的回復。
要使用多參數,只需對每個參數使用bindParam,或者使用命名參數:
$query="EXEC test :arg1, :arg2";
$stmt->bindParam(":arg1",$first_variable);
$stmt->bindParam(":arg2", $second_variable);
$stmt->prepare($query);
$stmt->execute();
另一種方法是將參數作為數組直接傳遞給execute()方法:
$stmt->execute(array(":arg1"=>$first_variable,":arg2"=>$second_variable
您還可以對查詢中的所有參數使用問號:
$query="EXEC test ?,?";
...
...
$stmt->bindParam(1, $first_variable);
$stmt->bindParam(2, $second_variable);
或直接在execute()內部:
$stmt->execute(array($first_variable, $second_variable));
我通常在PDO,IE中對參數使用問號
$stmt = $db->prepare("UPDATE table SET name=? WHERE id=?");
$stmt->execute(array($name, $id));
$affected_rows = $stmt->rowCount();
您可以在此處閱讀有關PDO查詢結構的詳細說明
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.