Invalid PHP ODBC Parameter Number

I am 100% new to this world of SQL / PHP / ODBC / FBI / TLA etc., so I apologize if what I ask is incredibly simple.

I use a stored procedure that uses a z / z database for long lengths to take the central zipcode and the given mile radius as 2 input parameters, and then returns an array of zip codes that are within a given mile radius. It works fine when I run it in my SQL viewer, but when I try to use php for this, I get invalid parameter errors.

$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); 

When I run such code, I get the error "Not enough parameters (1 must be 2)"

I tried different iterations of double quotes / single quotes around these input parameters, but they all either give me the above error, or this error:

"SQL error: [Microsoft] [SQL Server ODBC driver] Invalid parameter number, SQL status S1093"

A quick Google search leads me to believe that the second error means that there are a lot of parameters in proc, and how did I go from 1 to many, skipping the desired 2?

The database is on SQL 2000, if that matters.

Any ideas? Thanks for any help you can provide.

+4
source share
2 answers
 $zipcodes = odbc_execute($sp,array(" 14602, 35")); 

Must be

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

In your execution, you pass 1 the value of the array, "14602, 35", and your prepared statement searches for 2.

+3
source
 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); 
0
source

Source: https://habr.com/ru/post/1416624/


All Articles