简体   繁体   English

PHP中的SQL Server存储过程调用-无法获取返回到php的xml数据

[英]SQL Server Stored Procedure Call in PHP - Can't get xml data it returns back into php

Trying to call an SQL SERVER stored procedure from php. 试图从php调用SQL SERVER存储过程。 Think I've got it working but I can't get the data it returns back into php. 想想我已经工作了,但我无法获取返回到php的数据。 I'm copying my php code and also the sample SQL SERVER code below. 我正在复制我的PHP代码以及下面的示例SQL SERVER代码。

Believe my problem is how do get the data back from reportData? 相信我的问题是如何从reportData取回数据? mssql_execute() just returns boolean true. mssql_execute()仅返回布尔值true。 Looks to me like the procedure stores the data in reportData as xml. 在我看来,该程序将数据作为XML存储在reportData中。 However when i try to use mssql_bind() to get the data into reportData by reference I get warnings about converting from xml to varchar. 但是,当我尝试使用mssql_bind()通过引用将数据获取到reportData时,我收到有关从xml转换为varchar的警告。

My php Code 我的PHP代码

mssql_query("exec ZUSER.pSessionCreate @LoginName = 'admin', @Password = 'xxxx'", $Conn);
$proc = mssql_init("ZUSER.pAppraisal", $Conn);
$reportData="";
$portfolios=3014;
$date="08/19/2009";
mssql_bind($proc, "@reportData", &$reportData, SQLVARCHAR , TRUE, FALSE, 4000);
mssql_bind($proc, "@portfolios", $portfolios, SQLVARCHAR);
mssql_bind($proc, "@date", $date, SQLINT4 );
$result = mssql_execute($proc);

That will throw these errors. 这将引发这些错误。

Warning: mssql_execute() [function.mssql-execute]: message: Implicit conversion from data type xml to varchar is not allowed. Use the CONVERT function to run this query. 
Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed 

If I change the type of mssql_bind from SQLVARCHAR TO SQLTEXT then I get this error. 如果我将mssql_bind的类型从SQLVARCHAR更改为SQLTEXT,则会收到此错误。

Warning: mssql_execute() [function.mssql-execute]: message: Invalid parameter 1 ('@reportData'): Data type 0x23 is a deprecated large object, or LOB, but is marked as output parameter. Deprecated types are not supported as output parameters. Use current large object types instead. 

Also..if I don't use mssql_bind like this so that it doesn't try and return data to reportData it runs with no errors and returns true but I have no idea how I can get the data I need. 另外..如果我不这样使用mssql_bind,以便它不会尝试将数据返回给reportData,则它将运行而不会出错并且返回true,但是我不知道如何获取所需的数据。

mssql_bind($proc, "@reportData", $reportData, SQLVARCHAR);

In this case if I try and run this query after my call to mssql_execute I get this error. 在这种情况下,如果我在调用mssql_execute之后尝试运行此查询,则会收到此错误。

$result=mssql_query("select field1, field2, field3 from ZUSER.pAppraisal(@reportData)", $Conn);

Warning: mssql_query() [function.mssql-query]: message: Must declare the scalar variable "@reportData"

Example SQL Server Code: 示例SQL Server代码:

declare @SessionGuid uniqueidentifier
declare @portfolios nvarchar(max)
declare @date datetime
set @portfolios='3014'
set @date='08/19/2009'
exec ZUSER.pSessionCreate @LoginName = 'admin', @Password = 'xxxx'
declare @reportData xml
exec ZUSER.pAppraisal
    @reportData=@reportData out
    ,@portfolios = @portfolios
    ,@date = @date

select field1, field2, field3 from ZUSER.fAppraisal(@reportData)

您需要PHPSQL Server Native Client才能利用XML等新数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM