|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-06-27 11:59 UTC] jgeert1 at its dot jnj dot com
Description:
------------
I'm currently running PHP 5.5.12 and use the odbc functions to retrieving data from MS SQL Server databases. I've a query which runs fine (produces the expected result)when using this PHP version.
However I would like to upgrade PHP from 5.5.12 to 5.6.23. Installation went smoothly and all existing code seems to run fine on it except one db query, which now produces the error "[ODBC Cursor Library] Result set was not generated by a SELECT statement, SQL state SL004 in SQLGetData ...".
I've no idea what's causing it. It runs fine when using the old version of PHP, but with the latest one, it always fails. I also tried PHP 7.0.8, but it also produces the same error.
Test script:
---------------
$odbcmgt_dsn = "Driver={SQL Server};Server=MYSERVER;Database=MYDATABASE;";
$dbhandle = odbc_connect($odbcmgt_dsn,$odbcmgt_user,$odbcmgt_pwd,SQL_CUR_USE_ODBC);
$result = odbc_exec($dbhandle, $sql);
while( $row = odbc_fetch_array($result)) {
// data procession code
}
odbc_free_result($result);
odbc_close($dbhandle);
Expected result:
----------------
+/- 6000 rows of data
Actual result:
--------------
Error message: Warning: odbc_fetch_array(): SQL error: [Microsoft][ODBC Cursor Library] Result set was not generated by a SELECT statement, SQL state SL004 in SQLGetData in ....
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 12:00:01 2025 UTC |
Meanwhile after doing some additional testing, I noticed that I only have this error when a table has columns defined as "ntext" or "varchar(max)" or "nvarchar(max)" fields. If I remove these columns from my sql statement, the query runs fine again. When I create a dummy table like this: CREATE TABLE [dbo].[jg_test]( [id] [int] IDENTITY(1,1) NOT NULL, [test1] [int] NULL, [test2] [varchar](50) NULL, [test3] [varchar](max) NULL, [test4] [nvarchar](max) NULL, [test5] [int] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] just add some dummy data to it (in my case the varchar fields only contain "test"). use this code to access it: $user = "username"; $pwd = "password"; $dsn = "Driver={SQL Server Native Client 11.0};Server=myserver;Database=mydb;MARS_Connection=Yes;"; ini_set ('odbc.default_cursortype',SQL_CURSOR_FORWARD_ONLY); $dbhandle = odbc_connect($dsn,$user,$pwd,SQL_CUR_USE_DRIVER); $result = odbc_exec($dbhandle, "select * from dbo.jg_test"); while( $row = odbc_fetch_array($result)) { var_dump($row); } odbc_free_result($dbhandle); odbc_close($dbhandle); This will result in the error message: Warning: odbc_fetch_array(): SQL error: [Microsoft][SQL Server Native Client 11.0]Invalid Descriptor Index, SQL state S1002 in SQLGetData I know it's a different error message then the one posted before, but I'm sure that these are related to each other.