# [pdo_dblib] Correct TDS protocol version

- Thread: https://externals.io/message/122538
- Original archive: https://news-web.php.net/php.internals/122538
- Started by Saki Takamachi on 2024-03-02T14:19:53+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #122538 — Saki Takamachi — 2024-03-02T14:19:53+00:00

URL: https://externals.io/message/122538#122538

Hi internals,

There seems to be an error in the handling of pdo_dblib's TDS protocol version, so I'm thinking of fixing these. Through this email, I would like to discuss the appropriate time and method for correction.

— For your reference —
There are several derivatives of "SQL Server", with Microsoft SQL Server being the most popular. These communicate using the TDS protocol. However, the TDS protocol standards are not strictly unified, and the Sybase protocol and Microsoft SQL Server have different standards, so each is defined as a different "version" of the TDS protocol.
Therefore, pdo_dblib allows the user to specify a "version" for dsn and select which protocol version to use.
— End —

The related issue:
https://github.com/php/php-src/issues/13475

The types and details of protocol versions are explained in the FreeTDS user guide:
https://www.freetds.org/userguide/ChoosingTdsProtocol.html

Summarize the explanation.

4.2: Available for older Sybase and Microsoft SQL Servers
5.0: Available for new Sybase
7.0 - 7.4: Available for new Microsoft SQL Server

Notes:
- There's actually a version too called 4.6, which appears to be for Open SQL Server. However, I plan to explore this in a little more detail.
- It seems that there are two types of 5.0, so I will investigate this as well.

Now take a look at the pdo_dblib implementation in php-src:
https://github.com/php/php-src/blob/ffc6f192a8f475dfdff942bb22f509d1eefd0847/ext/pdo_dblib/dblib_driver.c#L447

Excerpt the incorrect part:
```
{"5.0",DBVERSION_70} /* FIXME: This does not work with Sybase, but environ will */
{"6.0",DBVERSION_70}
{"8.0",DBVERSION_72}
{"10.0",DBVERSION_100}
```

`DBVERSION_70` (meaning 7.0) is specified for 5.0 and 6.0. And as far as I can tell, there is no version called 6.0. (`DBVERSION_60` is also not defined.)

There is also no version 8.0, but according to the FreeTDS user guide, it appears that versions of FreeTDS older than 1.3 can specify this, as 7.1 was originally planned to be released as 8.0. However, PHP treats 8.0 as an alias for 7.2 rather than 7.1, which is incorrect anyway.

`DBVERSION_50`, which would be used for 5.0, is also not defined, but according to the following page, `DBVERSION_100` means 5.0.
https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20155_1251/html/newfesd/BABHHDEI.htm

Excerpt:

> DBVERSION_100 — DB-Library is running with TDS version 5.0 protocol

So remove 6.0, 8.0 and 10.0 and 5.0 should look like this:
```
{"5.0",DBVERSION_100}
```

These changes are definitely a BC break. Therefore, I would appreciate any feedback you may have, including which versions should I make changes to?

Regards.

Saki

---

## #122623 — Saki Takamachi — 2024-03-12T16:53:41+00:00

URL: https://externals.io/message/122538#122623 · In reply to: #122538

Hi,

I posted this just when the mailing list was having some trouble, so I'll add a reply just in case.

Regards.

Saki

---

## #122626 — Rob Landers — 2024-03-12T20:22:00+00:00

URL: https://externals.io/message/122538#122626 · In reply to: #122623

> Hi,
> 
> I posted this just when the mailing list was having some trouble, so I'll add a reply just in case.
> 
> Regards.
> 
> Saki

Instead of creating a BC break (which will probably affect older, less maintained libraries the most), why not create new constants and deprecate the old constants?

— Rob

---

## #122629 — Saki Takamachi — 2024-03-13T11:28:53+00:00

URL: https://externals.io/message/122538#122629 · In reply to: #122626

Hi Rob,

> Instead of creating a BC break (which will probably affect older, less maintained libraries the most), why not create new constants and deprecate the old constants?

I see, it makes sense to provide a transition period for users.

Would it be a good idea to deprecate it in 8.4 and discontinue it in 9.x?

Regardg.

Saki

---

## #122635 — Saki Takamachi — 2024-03-14T06:18:48+00:00

URL: https://externals.io/message/122538#122635 · In reply to: #122629

When I thought about it, these constants weren't being output to userland.

Just include "version=5.0" in th DSN....

Saki
