"Executing SQL directly; no cursor" error when using SCOPE_IDENTITY
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-04-28T15:28:51Z
Indexed on
2010/04/28
15:33 UTC
Read the original article
Hit count: 534
There wasn't much on google about this error, so I'm askin here. I'm switching a PHP web application from using MySQL to SQL Server 2008 (using ODBC, not php_mssql). Running queries or anything else isn't a problem, but when I try to do scope_identity (or any similar functions), I get the error "Executing SQL directly; no cursor". I'm doing this immediately after an insert, so it should still be in scope. Running the same insert statement then query for the insert ID works fine in SQL Server Management Studio. Here's my code right now (everything else in the database wrapper class works fine for other queries, so I'll assume it isn't relevant right now):
function insert_id(){
$x = $this->query_first("SELECT SCOPE_IDENTITY('session_log') as insert_id");
echo "($x)";
return $x;
}
query_first being a function that returns the first result from the first field of a query (basically the equivalent of execute_scalar() on .net).
The full error message: Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor., SQL state 01000 in SQLExecDirect in C:[...]\Database_MSSQL.php on line 110
© Stack Overflow or respective owner