Running MSSQL Stored Procedures via ODBC (And getting the results back) with PHP

kus

New Member
My work is in the process of moving all of our PHP web applications off of our Windows production web server to a new Linux server environment specifically for PHP apps. The sticky part is, several of the PHP applications we're running are using MSSQL databases, and therefore all the DB connectivity has to be re-written to use unixODBC/FreeTDS since PHP on Linux doesn't support mssql_connect() and it's related functions.I've gotten the connectivity down and basic queries execute fine. The problem I'm having is with running stored procedures, and replicating the mssql_init()/mssql_bind()/mssql_execute() functionality via ODBC.The problem area I'm working on is the following:\[code\]$sp = mssql_init('sp_Search', $this->_link);mssql_bind($sp, '@search', $this->_searchString, SQLVARCHAR);$results = mssql_execute($sp);\[/code\]I've read a bunch about the various ODBC functions and MSSQL functions. I've tried using the odbc_prepare()/odbc_execute() functions, to no avail (I always receive HY000 error codes from the SQL server). The closest I've come is this:\[code\]$results = odbc_exec($this->_link, "EXEC sp_Search @search='@this->_searchString'");\[/code\]Running that query ("EXEC sp_Search @search='blah'") via the MSSQL Management Console works perfectly, but via PHP it seems to work, but if I try to fetch the rows from the result set, I get "No tuples available at this result index" errors. And odbc_next_result() returns false no matter what.I also tried setting the cursor on the connection to SQL_CUR_USE_ODBC but that didn't help either. Does anybody have any experience doing this? Is it even possible, or is that functionality simply not available without the native MSSQL driver?Edit:Just to clarify, I have tried using odbc_prepare() and odbc_execute() as follows:\[code\]$results = odbc_prepare($this->_link, "{CALL sp_Search(?)}");$params = array($this->_searchString);odbc_execute($results, $params);\[/code\]This results in the following error:\[code\]Warning: odbc_execute(): SQL error: Failed to fetch error message, SQL state HY000 in SQLExecute\[/code\]
 
Back
Top