大家好,我有一个存储过程,我也在传递参数。
由于我传入参数的顺序与sql中的顺序不同,因此无法正常工作。我得到一个一般性的错误。我以正确的顺序传入参数,就像下面这行一样:
$stored_procedure_to_execute_with_parameters= 'Call '.$stored_procedure->name.'('.$parameter_argument_keys.')'; 这将转化为
Call save_user(':in_user_name', :in_user_password, :in_user_first_name') and so on.我在参数列表中使用SQL语言的过程是in_user_password,然后是in_user_first_name,最后是in_user_name。
Do参数需要以正确的顺序传递,因为存储过程本身。这是因为我正在从与所有参数匹配的对象创建插入
$results=array();
if(!is_null($stored_procedure->getParameter()) && count($stored_procedure->getParameter()>0))
{
$parameter_argument_keys= $this->parameterNamesOnly($stored_procedure->getParameter());
$stored_procedure_to_execute_with_parameters= 'Call '.$stored_procedure->name.'('.$parameter_argument_keys.')';
try{
$connection = Yii::app()->db;
$command = $connection->createCommand($stored_procedure_to_execute_with_parameters);
foreach ($stored_procedure->getParameter() as $parameter)
{
$command->bindValue(':'.$parameter->getName(),$parameter->getValue(),$parameter->getType());
}
$dataReader = $command->query();
$dataReader->setFetchMode(PDO::FETCH_ASSOC);
$results = $dataReader->readAll();
}
catch(Exception $e){
Yii::log('', CLogger::LEVEL_ERROR, $e->getMessage());
}发布于 2013-03-02 19:57:02
您确实需要以正确的顺序传递存储过程的参数。除了排序之外,存储过程无法知道哪个参数是哪个参数。
https://stackoverflow.com/questions/15174108
复制相似问题