Re: Stored Procedures
| From: | Steven Campbell | Date: | Tue, 29 Aug 2000 22:24:23 +0000 |
| Subject: | Re: Stored Procedures | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-2463@lists.php.net to get a copy of this message | ||
The way I do it is to return all results into a global cursor.
i.e. the last lines of the stored proc looks like this:
DECLARE status_cur CURSOR GLOBAL FAST_FORWARD FOR
<insert SELECT statement here>
In PHP, I do this:
$query = "BEGIN ";
$query .= "EXEC check_password '$Login_Name', '$Password',
'$SEQ_ID' ";
$query .- "OPEN status_cur ";
$query .- "FETCH NEXT FROM status_cur ";
// The line below is necessary iff one row is returned
// $query .- END ";
// Retrieve the first row returned in the cursor here...
/*
* Note that if your stored proc returns more than one result set, you
should do something in PHP
* to continue to retrieve rows from the cursor.
*/
$query .= "WHILE @@FETCH_STATUS = 0 ";
$query .= "BEGIN ";
$query .= "FETCH NEXT FROM status_cur ";
// Retrieve the additional results from the cursor here.
$query .- "END ";
Note that global cursors use lots of RAM, and should be deallocated
ASAP. I usually have a line like this at or near the top of each stored
proc that checks for and deallocates my cursors if it finds them. Even
better would be to make it part of the query to close and deallocate the
cursors when you're finished with them.
Something like this does the trick:
IF CURSOR_STATUS('global', 'status_cur') != -3
-- the cursor exists, so we gotta get rid of it
DEALLOCATE status_cur
Steven Campbell
Matthew Beers wrote:
>
> Has anyone had any success yet with MSSQL and stored procedures. I am
> trying to get data from out parameters from the sp, but so far no
> luck.
>