PDO存储过程的参数
问题描述:
如何使用PDO中的2个参数调用SQL Server的存储过程。PDO存储过程的参数
例如,在SQLServer的的提示:
EXEC测试 'ARG1', 'ARG2'
什么是PHP下一步与PDO?
在此先感谢您的回复。
答
我通常在PDO中使用问号来标记参数I.E.
$stmt = $db->prepare("UPDATE table SET name=? WHERE id=?");
$stmt->execute(array($name, $id));
$affected_rows = $stmt->rowCount();
您可以阅读PDO查询结构的一个很好的解释here
答
要使用muliple参数,只需要使用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));
'EXEC测试,' – 2014-10-17 14:51:09