Hi Terry,
I can explain the reason behind the behavior that you are seeing, as
well as a workaround. We will investigate ways to make this easier in
future versions.
The simple answer to why the resource seems to disappear, is because
it has.
When you perform a query, the actual result set object can either be
stored at the server (using SASQL_STORE_RESULT), or wholly transfered
to the client (using SASQL_USE_RESULT). In the example you are using
in the query() function, you have used SASQL_USE_RESULT so that the
entire result set object is copied over to the client.
The problem is that the result set that is returned by the
sasql_stmt_result_metadata() function implicitly uses
SASQL_STORE_RESULT. This means that the prepared statement object must
be around in order to use that result set since the actual result set
has not been copied to the client.
In your pquery() function, the prepared statement object ($stmt) is
defined locally in the pquery() function. Once that function
completes, PHP will automatically garbage collect the $stmt object.
The problem is that you have a reference ($rsx) to the metadata result
set that was part of the prepared statment object ($stmt) which no
longer exists. In order to use the result set after the prepared
statement object is gone, you would have to store the result set
object locally using something like SASQL_USE_RESULT. Unfortunately,
there is currently no way to do this for result sets returned by
sasql_stmt_result_metadata().
So for now the workaround is to convert the result set to an object or
array (using something like sasql_fetch_array() ) BEFORE the statement
object goes out of scope.
- Eric