参数编号无效,SQL状态为S1093 php odbc mssql [英] Invalid parameter number, SQL state S1093 php odbc mssql

查看:633
本文介绍了参数编号无效,SQL状态为S1093 php odbc mssql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我们有一个单身学生在做工作经验,他正在为我们做一个Wordpress原型(因为我们既没有Wordpress也没有PHP经验).

We have a uni student doing work experience at the moment and he's doing a Wordpress prototype for us (as we have neither Wordpress or PHP experience).

它在Windows服务器上运行,而Wordpress本身在mySQL中运行,因为我们所有现有的数据库都在MS SQL Server 2005/2008中,并且他正尝试使用以下代码在php页面中调用存储过程:

It's running on a Windows server and while Wordpress itself is running in mySQL, as all our existing databases are in MS SQL Server 2005/2008 and he's trying to call a stored procedure in a php page using this code:

$connection = odbc_connect('DB', 'UNAME', 'PWORD');

$request = odbc_prepare($connection, "CALL ProcName(?, ?, ?)");
if(!$request) die("Could not prepare statement:" . odbc_errormsg());


$result = odbc_execute($request, array("var1", "var2", "var3"));
if(!$result) die("Could not execute statement:" . odbc_errormsg());

存储过程如下:

ROCEDURE [dbo].[ProcName]
(@option1 varchar(50),
@option2  varchar(50),
@option3  varchar(50))
AS
... lots of logic end with...
select * from tblName

.net页面和Livelink CMS页面都使用该存储过程,并且该存储过程可以正常工作,但是当我们尝试从php调用存储过程时,它会出现以下错误:

The stored procedure is used both by .net pages and Livelink CMS pages and works correctly but when we try to call it from php, it errors with:

"odbc_execute(): SQL error: [Microsoft][ODBC SQL Server Driver]Invalid parameter number, SQL state S1093 in SQLDescribeParameter in C:\inetpub\wordpress\test.php on line 29"

奇怪的是,如果我们将过程调用重命名为一个不存在的存储过程,则它与完全相同的错误而不是存储过程中的错误无法被发现.

Strangely, if we rename the procedure call to a non existant stored procedure, it errors with exactly the same thing rather than a stored procedure cannot be found type of error.

我们可以直接运行sql,即从等中选择*",它将返回数据,但是我们不能调用存储过程(当然,我们将其用于所有操作!).

We can run sql directly i.e. "select * from etc" and it will return data but we can't call stored procedures (which we use for everything of course!).

知道他可能会出问题的地方吗?

Any idea where he could be going wrong?

推荐答案

当我从Java EE/Hibernate执行本机SQL查询时,遇到了相同的错误.我在查询来自表的SELECT Count(1)",但犯了一个错误,将映射类作为参数包括在内. COUNT(1)返回一个整数,因此不需要进行映射.希望能有所帮助.

I got the same error when I was doing an native SQL query from Java EE/Hibernate. I was querying "SELECT Count (1) From Table" and I made the mistake of including a mapping class as a parameter. COUNT(1) returns an integer, so it doesn't need to be mapped. Hope that helps.

这篇关于参数编号无效,SQL状态为S1093 php odbc mssql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆