I am using PHP 5.1.6 on a Linux server and need to access a MS SQL Server 2005 database.
The PHP docs at http://us2.php.net/manual/en/ref.mssql.php say installing FreeTDS is a requirement for using the mssql extensions.
FreeTDS is installed and configured for connection to a MS SQL 2005 server on my local network. I'm able to use the FreeTDS tool "tsql" to access the MS SQL 2005 server and successfully "select * from my_table" or "exec my_stored_proc" and see a dataset returned.
Attempting to access the same MS SQL 2005 server from PHP, I can successfully "select * from table", but I cannot "exec my_stored_proc".
The following PHP code runs successfully:
$conn = mssql_pconnect($server,$user_id,$user_pswd);
$query = "select TOP 5 description from my_table";
$result = mssql_query($query, $conn);
while($line = mssql_fetch_row($result)){
echo "$line[0]<BR>";
}
mssql_free_result($result);
mssql_close($conn);
But, when I try to use the following code to execute a stored procedure that should return the same dataset:
$conn = mssql_pconnect($server,$user_id,$user_pswd);
$sp = mssql_init("my_stored_proc",$conn);
mssql_execute($sp);
while($line = mssql_fetch_row($sp)){
echo "$line[0]<BR>";
}
mssql_free_result($sp);
mssql_close($conn);
the following error occurs executing the mssql_init() statement:
"Warning: mssql_init(): supplied argument is not a valid MS SQL-Link resource in [filepath/filename].php"
I've tried both mssql_connect() and mssql_pconnect(), but I get the same error with either. I don't understand why the resource ($conn) returned by mssql_pconnect() or mssql_connect() is seen as "a valid MS SQL-Link resource" by mssql_query(), but not by mssql_init().
Thanks for your time. Any ideas or suggestions greatly appreciated....