将XML数据作为输入传递给存储过程

时间:2013-08-05 12:11:28

标签: php sql sql-server sql-server-2008

我的XML数据/记录传递给SQL存储过程,SP成功运行已加载的记录。但有一段时间我得到了以下错误消息

错误

Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in

MS SQL Store过程

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddEmployee] (@XmlString ntext)
AS
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET NUMERIC_ROUNDABORT OFF
DECLARE @XmlInput XML;
SET @XmlInput = CAST(@XMLHeader AS XML)
INSERT INTO Employee
(
    ID,
    EmpName,
    Sal
)
Select
T.N.value('ID[1]', 'varchar(250)') as CompanyName,
T.N.value('EmpName[1]', 'varchar(250)') as WebsiteUrl,
T.N.value('Sal[1]', 'varchar(250)') as PrimaryServices
from @XmlInput.nodes('/Record/Emp') as T(N)

PHP代码段

$procName = "AddEmployee";
$xml_data = "<record><Emp><ID>6</ID><EmpName>ganesh</EmpName><Sal>6500</Sal></Emp><Emp><ID>7</ID><EmpName>jayachandran</EmpName><Sal>7500</Sal></Emp><Emp><ID>8</ID><EmpName>kotis</EmpName><Sal>8500</Sal></Emp></Record>"
$params[0][0] = "XmlString";
$params[0][1] = $xml_data;
$params[0][2] = SQLVARCHAR;

$proc = mssql_init(proc_name,$connid);
for($i=0;$i<count($params);$i++){
    $rtn = mssql_bind($proc,'@'.$params[$i][0],$params[$i][1],$params[$i][2]);      
}
$rtn_status = mssql_execute($proc);

0 个答案:

没有答案