嗨我有MySql 5.6编写的存储过程,它有2个输入参数和2个输出参数,而我从我的php代码调用这个存储过程时抛出以下错误:
错误代码:1414。例程 sp name 的
OUT
或INOUT
参数2不是{{1}中的变量或NEW
伪变量触发器。
我正在使用以下代码:
BEFORE
我在SP下面使用
public function get_brand_code_nd_model($phonemake,$phonemodule)
{
$db1=$this->load->database('fonesherpa', TRUE);
$query = $db1->query("Call GetModelnBrandCodeFromName('$phonemake','$phonemodule',@BrandCode,@ModelCode)");
}
请帮我解决这个问题。
答案 0 :(得分:0)
我已经对SP进行了更改并删除了输出参数,然后从PHP代码中调用它现在工作正常。我在SP中做了哪些更改:
DELIMITER $$
CREATE DEFINER="root"@"localhost" PROCEDURE "GetModelnBrandCodeFromName"(
_BrandName nvarchar(100),
-- out _BrandCode int ,
_ModelName nvarchar(100)
-- out _ModelCode int
)
BEGIN
-- Declare variables to store result set during query execution :
declare temp_IntBrandC int;
declare temp_IntModelC varchar(100);
Set temp_IntBrandC= (Select CompanyCode From MasterMobileBrand where CompanyName =_BrandName);
-- select @IntBrandc;
-- If not, then check if it matches the user agent name
-- that is usually passed in HTTP headers
-- For e.g. when Blackberry is the company name the User Agent name
-- is RIM
IF (temp_IntBrandC is NULL) then
Begin
-- select IntBrandC;
Set temp_IntBrandC = (Select CompanyCode From MasterMobileBrand where UserAgentName =_BrandName);
-- print @Intbrandc
End;
end if;
IF (temp_IntBrandC is not NULL) then
Begin
-- select @IntBrandC;
-- SET _BrandCode = temp_IntBrandC ;
-- select _brandcode;
-- select Brandcode from mobilemodel where brandcode=temp_IntBrandC limit 1;
-- Print @brandcode
SET temp_IntModelC = (select ModelCode from MobileModel where BrandCode = temp_IntBrandC and ModelName like CONCAT('%',_ModelName,'%') limit 1);
-- select @IntModelc;
-- Insert if Model Code does not exist in database
If(temp_IntModelC is NULL) then
Begin
-- select "hello";
set @maxmobcode=(Select (MAX(ModelCode) + 1) From MobileModel);
Insert Into MobileModel(companyname, ModelCode, BrandCode, ModelName, ImageName, IsJavaPhone)
Values(_BrandName,@maxmobcode, temp_IntBrandC, _ModelName, NULL, False);
-- get newly inserted ModelCode
SET temp_IntModelC = (select ModelCode from MobileModel where BrandCode = temp_IntBrandC and ModelName like CONCAT('%',_ModelName,'%') limit 1);
--
-- Print @IntModelc
End;
end if;
If(temp_IntModelC is not NULL) then
Begin
-- SET _ModelCode = temp_IntModelC;
select Brandcode,Modelcode from mobilemodel where modelcode=temp_IntModelC limit 1;
-- select _brandcode;
-- Print @Modelcode
End;
Else
Begin
-- SET _ModelCode = -1;
set temp_IntModelC=-1;
select temp_IntModelC as ModelCode;
End;
end if;
End;
Else
Begin
-- SET _BrandCode = -1;
-- SET _ModelCode = -1;
-- select _brandcode,_ModelCode;
set temp_IntBrandC=-1;
set temp_IntModelC=-1;
select temp_IntBrandC as Brandcode,temp_IntModelC as Modelcode;
-- print @brandcode
-- print @modelcode
end;
end if;
End
和它的PHP代码:
public function get_brand_code_nd_model($phonemake,$Format,$phonemodule)
{
$query = $db1->query("Call GetModelnBrandCodeFromName('$phonemake','$phonemodule')");
if($query->num_rows() == 0)
{
header('HTTP/1.1 404 Content not found');
//echo "Hi";
//log_message('error','Content not found',TRUE);
}
if($Format=='json' || $Format=='JSON' || empty($Format))
{
//echo "hi";
return json_encode($query->result_array());
}
if($Format=='xml' || $Format=='XML')
{
$this->load->library('xml_writer');
foreach ($query->result_array() as $value)
{
$xml = Xml_writer::createXML('activation', $value);
echo $xml->saveXML();
}
}