php / php/php-src

odbc_fetch_*() fails to fetch SQL Server text fields with SQL_CUR_USE_ODBC

Open
#15,219 17 comments 0 reactions 1 assignee View on GitHub

@cmb69 is already working on this.

Since Aug 5, 2024.

Bug Extension: odbc Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

$conn = odbc_connect('DRIVER={SQL Server Native Client 11.0};SERVER=LOCALHOST\SQLSERVER;DATABASE=OIDPLUS;charset=UTF-8;Client_CSet=UTF-8;Server_CSet=UTF-8', 'sa', '123456', SQL_CUR_USE_ODBC);
$res = odbc_exec($conn, "select description from my_objects");
while ($row = odbc_fetch_object($res)) {
	var_dump($row);
}
echo odbc_close($conn);

Resulted in this output:

(Nothing; odbc_fetch_object is false)

But I expected this output instead:

Printed array with descriptions

The bug only happens if odbc_connect() has SQL_CUR_USE_ODBC and it ONLY fails if you fetch exactly one column with the text data type. If you fetch a text row and another row, then it works!

  • select description from my_objects does NOT work
  • select id, description from my_objects WORKS
  • select id from my_objects WORKS

System:

  • Windows 10 Pro
  • SQL Server 2022
PHP Version

PHP 8.3.6 (also tested with PHP 8.4 Alpha 4)

Operating System

Windows 10 x64

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.