|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63498 Wrong order of options in sqlsrv_query can throw "Invalid cursor state" error
Submitted: 2012-11-12 19:26 UTC Modified: 2020-02-07 14:51 UTC
Avg. Score:2.4 ± 0.8
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: oleg at mastak dot fi Assigned: cmb (profile)
Status: Closed Package: sqlsrv (PECL)
PHP Version: 5.4.8 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: oleg at mastak dot fi
New email:
PHP Version: OS:


 [2012-11-12 19:26 UTC] oleg at mastak dot fi
In sqlsrv_query function, fourth parameter is array that can contain following three options with corresponding keys :  QueryTimeout, SendStreamParamsAtExec	, Scrollable

You would assume that you can specify options in any order, however, this is not true.

If you run following script, you will hit unspecified error "[Microsoft][ODBC Driver Manager] Invalid cursor state"

However, if you change order to:
$config = array(
    'Scrollable'    => SQLSRV_CURSOR_KEYSET,
    'QueryTimeout'  => 2,

then everything works OK.

As this is illogical, I think this is bug and should be fixed.

Test script:
$link = sqlsrv_connect ( 'serverName\sqlexpress', $connectionInfo );

$config = array(
    'QueryTimeout'  => 2,
    'Scrollable'    => SQLSRV_CURSOR_KEYSET,

$query  = "CREATE TABLE #MY_TABLE([var1] [bigint] NOT NULL);";
$result = sqlsrv_query($link,$query,array(),$config) or die("ERROR ". print_r(sqlsrv_errors(),true));

Expected result:

Actual result:
ERROR Array ( [0] => Array ( [0] => 24000 [SQLSTATE] => 24000 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Invalid cursor state [message] => [Microsoft][ODBC Driver Manager] Invalid cursor state ) )


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-12 21:11 UTC]
-Package: MSSQL related +Package: sqlsrv
 [2012-11-12 21:11 UTC]
Assigned to the right extension
 [2012-11-12 21:33 UTC]
Thanks for reporting this.  We will look into it.
 [2020-02-07 14:51 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-02-07 14:51 UTC]
If you still experience this issue, please file a bug report at
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Aug 12 16:01:25 2020 UTC