PDA

View Full Version : PHP/ MSSQL & a stored procedure...




ChoMomma
Jun 11, 2007, 02:57 PM
Anyone have experience with PHP, MSSQL and excuting a stored procedure?

I have Mac-mini running a small corporate intranet site, I have installed PHP 5 with FreeTDS so that I can access MSSQL databases that run on other company servers.

My problem is that I want I have a search form that queries a database fine, but I have a stored procedure that modifies the input on one field to bounce it off of a list of known abbreviations (ex: OS = Operating System). The stored procedure takes the input of the field and then outputs a string like db.field LIKE %Operating% OR db.field LIKE %System% OR db.field LIKE %OS%

That string needs to be put into the existing database query.

$sql = mssql_query("SELECT * FROM DBTable WHERE $storedprocedure ORDER BY x DESC");


However when I try to drop my string into that query it always complains about syntax error before ORDER.

????



jeremy.king
Jun 11, 2007, 03:42 PM
To exec a stored proc, you will need to use the following functions

mssql_init() (http://us.php.net/mssql_init)
mssql_bind() (http://us.php.net/mssql_bind)
mssql_execute() (http://us.php.net/mssql_execute)


Problem is this will require two SQL calls, one for the stored proc and one for the query. The only way you could do it with one query is to write another stored proc that references the first and executes your SELECT statement.