|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76732 Unable to fetch text and varchar(max) when procedure returns more result sets
Submitted: 2018-08-12 13:22 UTC Modified: 2020-10-05 12:48 UTC
Avg. Score:4.7 ± 0.7
Reproduced:22 of 22 (100.0%)
Same Version:6 (27.3%)
Same OS:16 (72.7%)
From: honza dot hink at gmail dot com Assigned:
Status: Verified Package: ODBC related
PHP Version: 7.3 OS: Windows 10
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: honza dot hink at gmail dot com
New email:
PHP Version: OS:


 [2018-08-12 13:22 UTC] honza dot hink at gmail dot com
odbc_fetch_array() reports error: SQL error: [Microsoft][SQL Server Native Client 11.0]Invalid Descriptor Index, SQL state S1002 in SQLGetData in ...

It is related to Bug #73725, that has been partially solved, but it remains by this circumstances:

This error occurs on reading result with two conditions at the same time.
First condition:
- SQL syntax contains more than one command (select or execute)
- SQL command contains anything extra, f.e. "set nocount on execute ..."
- SQL command contains any comment, f.e. "/* any comment */ select ..."
- SQL command calls a procedure that returns more than one result

Second condition:
- one of sql results contains column type text or not empty varchar(max)

If one condition is not true, then it works OK.
There are differences between drivers "SQL Server" and "SQL Server Native Client". One doesn't like text type if it is not the last column, another driver doesn't like not empty varchar(max).
My example contains both features, so it gives an error regardless used driver.

Test script:
	header("Content-Type: text/html; charset=utf-8");
	$res1=odbc_do($con,"create procedure #p as
		select convert(text,'text 1') converted_to_text, 1 i, convert(varchar(max),'text 1') converted_to_varchar_max
		select convert(text,'text 2') converted_to_text, 1 i, convert(varchar(max),'text 2') converted_to_varchar_max
	$res2=odbc_do($con,"execute #p");

Expected result:
    [converted_to_text] => text 1
    [i] => 1
    [converted_to_varchar_max] => text 1

Actual result:
<br />
<b>Warning</b>:  odbc_fetch_array(): SQL error: [Microsoft][SQL Server Native Client 11.0]Invalid Descriptor Index, SQL state S1002 in SQLGetData in <b>F:\EclipseWorkspaces\Ramses\www\pokus.php</b> on line <b>9</b><br />


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-13 11:06 UTC]
-Package: MSSQL related +Package: ODBC related
 [2019-08-24 08:04 UTC] honza dot hink at gmail dot com
This case is bewhiskered, nobody concerns. Build a headstone.
 [2020-10-05 12:30 UTC]
-Status: Open +Status: Verified
 [2020-10-05 12:30 UTC]
I can confirm this issue with ODBC 17 Driver for SQL Server.
Other drivers are likely affected as well.  The problem is
that the odbc extension mixes SQLBindCol() and SQLGetData()
even for drivers which do not support SQL_GD_ANY_COLUMN,
whereas PDO_ODBC gets that right[1].

[1] <>
 [2020-10-05 12:48 UTC]
-PHP Version: 7.2.8 +PHP Version: 7.3
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 13:01:30 2024 UTC