我正在使用Adodb PHP库来处理数据库功能。大多数功能都是使用存储过程处理的。但是,在少数情况下,我需要编写快速自定义查询来完成流程。
代码:
$Result = array();
$this->DB->SetFetchMode(ADODB_FETCH_ASSOC);
$Result = $this->DB->PrepareSP("UPDATE Member SET FirstName = '" . $param['FirstName'] . "', LastName = '" . $param['LastName'] . "', Email = '".$param['Email']."', DateOfBirth = '".$param['DateOfBirth']."', HoroscopeID = ".$param['HoroscopeID'].", Gender = '".$param['Gender']."', CountryID = ".$param['CountryID']." WHERE ID = ".$param['MemberId'].";SELECT @@IDENTITY AS AffectedRows;");
$Result = $this->DB->GetArray($Result);
结果:
array (size=1)
0 =>
array (size=1)
'AffectedRows' => null
我也尝试过:
$this->DB->affected_rows();
每次都返回0。我已经回应了内部查询并在navicat上运行,它运行正常。但是,当它通过代码调用时,它不会更新任何记录。
答案 0 :(得分:0)
以下是如何在ADOdb中访问存储过程输出数据:
/*
* Your stored procedure preparation returns a handle
*/
$procedure = $this->DB->prepareSp("your statement...");
/*
* You prepare and set an output parameter to receive your affected rows
* The name of the parameter matches the stored procedure variable
*/
$outParameterName = 'AffectedRows';
$outParameterValue = 0;
$ok = $this->DB->outParameter($procedure,$outParameterName,$outParameterValue);
/*
* Execute the procedure handle , it is an update so a resultset is not returned
*/
$result = $this->DB->execute($procedure);
/*
* The value of the Affected rows is now available in your out Parameter value
*/
print "AffectedRows IS NOW $outParameterValue";