[TriLUG] Linux, Apache, Php, MS SQL, ODBC and Store Procedures

matt at noway2.thruhere.net matt at noway2.thruhere.net
Wed Jan 19 17:16:49 EST 2011


Group,

I am writing an Apache+PHP application that runs on Linux.  I have built
PHP with the unixODBC and freeTDS.  I am able to establish a database
connection  to the MS SQL Server.  I would like to execute a vendor
supplied stored procedure that returns as a result set.  I can execute the
stored procedure in the terminal (iSQL) and I get the proper results.

If I try to execute the procedure as follows in (1), there is the
appropriate delay as the query executes, but there is no result set.
(example 1)
$connect = odbc_connect("MSSQLTest", "user", "password");
$query = "Execute <the stored procedure>";
# perform the query
$result = odbc_exec($connect, $query);

# fetch the data from the database
while(odbc_fetch_row($result)) { .... }

Nothing is returned.

If I change the format to the following:
$stmt = odbc_prepare($connect, "{CALL <the stored procedure}");
$result = odbc_execute($stmt, array() );

I get result = TRUE indicating that the procedure executed, but there is
no result set.

Does anybody know how to obtain the result set from the stored procedure
in MS SQL Server using Linux and ODBC?




More information about the TriLUG mailing list