php / php-src

The PHP Interpreter
https://www.php.net
Other
37.96k stars 7.73k forks source link

pdo_dblib wrong protocol version 5.0 #13475

Open hanisko opened 6 months ago

hanisko commented 6 months ago

Description

The following code:

<?php
$connection = new PDO('dblib:version=5.0;host=example', 'username', 'password');

Problem is with Sybase System 10 and above > use protocol version 5.0 but here link

{"5.0",DBVERSION_70} /* FIXME: This does not work with Sybase, but environ will */

PHP Version

PHP 8.2

Operating System

No response

SakiTakamachi commented 6 months ago

I'll confirm this by early next week.

SakiTakamachi commented 6 months ago

There are so many ways to install sybase that I don't know which is the correct one... Is there a recommended method?

hanisko commented 6 months ago

There are so many ways to install sybase that I don't know which is the correct one... Is there a recommended method?

You can install it via enterprise edition: https://www.sap.com/products/technology-platform/sybase-ase/trial.html

SAP ASE, enterprise edition, contains all options for your evaluation. It expires after 90 days and can be used only in nonproduction environments.

hanisko commented 6 months ago

Here is repository, which simulate 5.0 protocol bug https://github.com/hanisko/php_dblib (sybase 16 + latest php)

SakiTakamachi commented 6 months ago

@hanisko Thank you, docker-compose.yml in your repository was very helpful. But I'm sorry. I actually just moved and my internet is incredibly slow until March 7th. I'm trying to download sybase, but I suspect it will be March 7th before that...

It may not be until March 7th that we can properly investigate this issue.

SakiTakamachi commented 6 months ago

Suddenly, my unstable internet connection suddenly became faster and by chance I was able to download all of sybase. I was able to reproduce it in my environment as well. I'll investigate this issue.

SakiTakamachi commented 6 months ago

@hanisko

I got it.

I will write from the conclusion, please try specifying 10.0 instead of 5.0. Perhaps it will do what you want.


in detail

Excerpt from the following page: https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20155_1251/html/newfesd/BABHHDEI.htm

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

I've found some of the same information on other sites, so it seems certain that DBVERSION_100 means 5.0.

But PHP seems to have been interpreting this as 10.0 for a long time. https://github.com/php/php-src/blob/61d8c7767649844830c0d32af426257280531f8d/ext/pdo_dblib/dblib_driver.c#L466

Fixing this will definitely result in a BC Break, so it can't be fixed, at least not on the stable branch. It may be possible to fix it in the master branch (future 8.4), but first I need to investigate the scope of the impact of fixing this.

hanisko commented 6 months ago

Yes, you are right, "10.0" solved the issue, it doesn't generate "Error: 1621, Severity: 18, State: 1" into sybae logs.

Comment on line 450 "FIXME: This does not work with Sybase" and pointig version 5.0, 6.0, 7.0 to same value "DBVERSION_70" confused me. Maybe just better documentation for "version" values in dsn will be helpfull https://www.php.net/manual/en/ref.pdo-dblib.connection.php

This comment was also confusing https://www.php.net/manual/en/ref.pdo-dblib.connection.php#118644 where is statement about "version from dsn" = "tds version" which is not correct with 5.0 protocol (only info in docs about version in dsn)

I hope it will be better documented or fixed in future versions.

Thanks for your help :-)

SakiTakamachi commented 6 months ago

I have posted about this issue to the mailing list. https://externals.io/message/122538