views:

209

answers:

2

I need to call two stored procedures in sequence via ODBC in PHP:

#run stored procedure 1
$query = "Shipped_Not_Shipped_Rep ".$_GET['rep_id'];
$result = odbc_exec($dbh, $query);
odbc_result_all($result);

#run stored procedure 2
$query = "Shipped_Not_Shipped_Account ".$_GET['account_id'];
$result = odbc_exec($dbh, $query);
odbc_result_all($result);

I'm getting this error in PHP after the second stored procedure call:

Warning: odbc_exec() [function.odbc-exec]: SQL error: [unixODBC][FreeTDS][SQL Server]Invalid cursor state, SQL state 24000 in SQLExecDirect

If I re-arrange the order I call the stored procedures, it is always the second that errors. Is there a way to, idk, reset the cursor position between calls? A little out of my element here.

A: 

Try accessing the results using different cursors, $result1 and $result2.

Dmitry
Didn't make a difference. Thanks though.
weotch
+1  A: 

Open two handles to the database. ODBC probably maintains the cursor in the handle.

wallyk
Opening two at the same time and using one for each didn't work. But closing the connection and creating a new one between queries did. This isn't an ideal answer, I'm still poking around. My local install, which uses a different ODBC driver, works fine running the two in sequence. So maybe there is something there...
weotch
Well, further research didn't get me anywhere. So I'm closing and reopening the db with each connection. Seems like an expensive operation, but at least what I'm doing doesn't require peak performance.
weotch