PHP ODBC 存储过程参数编号无效


PHP ODBC Stored Procedure Invalid Parameter Number

我是 SQL/PHP/ODBC/FBI/TLA 等世界的 100% 全新人,所以如果我的要求非常基本,我深表歉意。

我正在使用一个存储过程,该过程使用经度/经度邮政编码数据库将中央邮政编码和给定英里半径作为 2 个输入参数,然后返回该给定英里半径内的邮政编码数组。当我在SQL查看器中运行它时,它可以完美运行,但是当我尝试使用php来做同样的事情时,我只会收到无效的参数错误。

$connstr = "Driver={SQL Server};Server=MyServer;Database=MyDatabase;";
$conn = odbc_connect($connstr, "Name", "PW");
$query_string = " CALL FindZipCodeWithinRadius(?,?)  ";
$sp = odbc_prepare($conn, $query_string);
$zipcodes = odbc_execute($sp,array(" 14602, 35"));
print_r($zipcodes);

当我像这样运行代码时,我收到错误"参数不足(1 应该是 2)"

我已经尝试了围绕这些输入参数的不同双引号/单引号迭代,但它们都给了我上述错误或此错误:

"SQL 错误: [Microsoft][ODBC SQL 服务器驱动程序]参数编号无效,SQL 状态 S1093"

快速的谷歌搜索让我相信第二个错误意味着有太多的参数被读入 proc,那么我是如何在跳过所需的 2 的同时从 1 到很多的呢?

如果这有区别,则数据库位于 SQL 2000 上。

有什么想法吗?感谢您提供的任何帮助。

$zipcodes = odbc_execute($sp,array(" 14602, 35"));

应该是

$zipcodes = odbc_execute($sp,array("14602", "35"));

在执行中,您传递了 1 个数组值"14602, 35",并且您准备好的语句正在寻找 2。

Below is the Code to execute MS SQL Stored Procedure in PHP
$DBConnString="DRIVER={SQL Server};SERVER=localhost;DATABASE=ERPDev";
$DBUsername="sa";
$DBPswd="";
$DBConnect = odbc_connect($DBConnString, $DBUsername, $DBPswd);  
$Param1 = '2';
$query_string = "P_Test[$Param1]";
$ResultSet = odbc_prepare($DBConnect, $query_string);
odbc_execute($ResultSet);
// odbc_result_all($ResultSet);
while($obRows = odbc_fetch_object($ResultSet))
{
    print $obRows->UserId." - ";
    print $obRows->UserFirstName." - ";
    print $obRows->UserLastName."<br />";
}
odbc_free_result($ResultSet);
odbc_close($DBConnect);