php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74477 can not connect to sybase with pdo_dblib
Submitted: 2017-04-20 07:45 UTC Modified: 2017-05-23 15:18 UTC
From: fuzzywy at 163 dot com Assigned:
Status: Not a bug Package: PDO DBlib
PHP Version: 7.1.4 OS: centos7
Private report: No CVE-ID: None
 [2017-04-20 07:45 UTC] fuzzywy at 163 dot com
Description:
------------
The problem is that i can connect sybase with freetds, while pdo_dblib get error.

===
freetds.conf
[sybase]
        host = 7.140.28.88
        port = 26401
        tds version = 5.0

===
test script
php -r "new PDO('dblib:host=7.140.28.88:26401;dbname=dwhdb','dcbo','dcbo');"



Expected result:
----------------
connect to sybase server

Actual result:
--------------
PDOException thrown
Fatal error: Uncaught PDOException: SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server (severity 15) in Command line code:1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-24 18:59 UTC] adambaratz@php.net
-Status: Open +Status: Feedback
 [2017-04-24 18:59 UTC] adambaratz@php.net
Is it possible to use a different TDS version? There's a comment in the source suggesting that 5.0 isn't supported:
https://github.com/php/php-src/blob/PHP-7.1.4/ext/pdo_dblib/dblib_driver.c#L312

If that doesn't work, it would help to know if this was a regression between PHP versions. I don't have a local instance of Sybase, so this may be difficult to help debug, but that might point the way.
 [2017-04-25 00:56 UTC] fuzzywy at 163 dot com
I've been aware of the issue so i checked the source code in 5.5.15
(in which version my program works well).

https://github.com/php/php-src/blob/PHP-5.5.15/ext/pdo_dblib/dblib_driver.c

It's same as the code in 7.1.4 that there's a comment in version 5.0。

And i also test it in 7.0.x, change the global tds version in my freetds.conf to 4.2, both can not work。
 [2017-04-28 17:29 UTC] adambaratz@php.net
Are you familiar with TDSDUMP environment variable?
http://www.freetds.org/userguide/logging.htm

Try doing this for both PHP versions:
TDSDUMP="freetds.log" php -r "new PDO('dblib:host=7.140.28.88:26401;dbname=dwhdb','dcbo','dcbo');"

If you share both log files, I might be able to help debug.
 [2017-05-02 02:11 UTC] fuzzywy at 163 dot com
FYI, thanks!

--------------------------------------------------
log.c:196:Starting log file for FreeTDS 0.91
	on 2017-05-02 01:50:40 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0x329e160, UTF-8)
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
iconv.c:394:tds_iconv_open: done
net.c:205:Connecting to 7.140.28.88 port 26401 (TDS version 5.0)
net.c:270:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:310:tds_open_socket() succeeded
util.c:156:Changed query state from DEAD to IDLE
net.c:741:Sending packet
0000 02 00 02 00 00 00 00 00-70 72 6f 6d 6f 74 65 2e |........ promote.|
0010 63 61 63 68 65 2d 64 6e-73 2e 6c 6f 63 61 6c 00 |cache-dn s.local.|
0020 00 00 00 00 00 00 17 64-63 62 6f 00 00 00 00 00 |.......d cbo.....|
0030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0040 00 00 00 00 00 04 64 63-62 6f 00 00 00 00 00 00 |......dc bo......|
0050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0060 00 00 00 00 04 33 37 35-33 00 00 00 00 00 00 00 |.....375 3.......|
0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0080 00 00 00 04 03 01 06 0a-09 01 00 00 00 00 00 00 |........ ........|
0090 00 00 00 00 50 48 50 20-66 72 65 65 74 64 73 00 |....PHP  freetds.|
00a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00b0 00 00 0b 37 2e 31 34 30-2e 32 38 2e 38 38 3a 32 |...7.140 .28.88:2|
00c0 36 34 30 31 00 00 00 00-00 00 00 00 00 00 00 00 |6401.... ........|
00d0 00 11 00 04 64 63 62 6f-00 00 00 00 00 00 00 00 |....dcbo ........|
00e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00f0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0180 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0190 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01b0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01d0 00 06 05 00 00 00 44 42-2d 4c 69 62 72 61 72 79 |......DB -Library|
01e0 0a 05 00 00 00 00 0d 11-75 73 5f 65 6e 67 6c 69 |........ us_engli|
01f0 73 68 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |sh...... ........|

net.c:741:Sending packet
0000 02 01 00 61 00 00 00 00-00 00 00 00 00 00 0a 00 |...a.... ........|
0010 00 00 00 00 00 00 00 00-00 00 00 00 00 75 74 66 |........ .....utf|
0020 38 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |8....... ........|
0030 00 00 00 00 00 00 00 00-00 00 00 04 01 35 31 32 |........ .....512|
0040 00 00 00 03 00 00 00 00-e2 16 00 01 09 00 08 0e |........ ........|
0050 6d 7f ff ff ff fe 02 09-00 00 00 00 02 68 00 00 |m....... .....h..|
0060 00                     -                        |.|

token.c:328:tds_process_login_tokens()
net.c:555:Received header
0000 04 01 00 59 00 00 00 00-                        |...Y....|

net.c:609:Received packet
0000 04 01 00 59 00 00 00 00-e3 07 00 03 04 75 74 66 |...Y.... .....utf|
0010 38 00 e3 09 00 04 03 35-31 32 03 35 31 32 ad 16 |8......5 12.512..|
0020 00 05 05 00 00 00 0c 53-51 4c 20 41 6e 79 77 68 |.......S QL Anywh|
0030 65 72 65 10 00 00 00 e2-16 00 01 09 00 08 0e 61 |ere..... .......a|
0040 01 ff ff fe e6 02 09 07-fe 3f 9e e6 68 00 00 0a |........ .?..h...|
0050 fd 00 00 01 00 7c 89 19-00                      |.....|.. .|

token.c:337:looking for login token, got  e3(ENVCHANGE)
token.c:122:tds_process_default_tokens() marker is e3(ENVCHANGE)
token.c:2493:server indicated charset change to "utf8"
iconv.c:988:setting server single-byte charset to "UTF-8"
dblib.c:327:db_env_chg(0x329e160, 3, , utf8)
token.c:337:looking for login token, got  e3(ENVCHANGE)
token.c:122:tds_process_default_tokens() marker is e3(ENVCHANGE)
token.c:2477:changing block size from 512 to 512
dblib.c:327:db_env_chg(0x329e160, 4, 512, 512)
token.c:337:looking for login token, got  ad(LOGINACK)
token.c:373:server reports TDS version 5.0.0.0
token.c:375:Product name for 0x5000000 is unknown
token.c:337:looking for login token, got  e2(CAPABILITY)
token.c:122:tds_process_default_tokens() marker is e2(CAPABILITY)
token.c:337:looking for login token, got  fd(DONE)
token.c:122:tds_process_default_tokens() marker is fd(DONE)
token.c:2339:tds_process_end: more_results = 0
		was_cancelled = 0
		error = 0
		done_count_valid = 0
token.c:2355:tds_process_end() state set to TDS_IDLE
token.c:2370:                rows_affected = 1673596
token.c:438:tds_process_login_tokens() returning TDS_SUCCEED
mem.c:615:tds_free_all_results()
util.c:156:Changed query state from IDLE to QUERYING
util.c:156:Changed query state from QUERYING to PENDING
net.c:741:Sending packet
0000 0f 01 00 2c 00 00 00 00-21 1f 00 00 00 00 73 65 |...,.... !.....se|
0010 74 20 74 65 78 74 73 69-7a 65 20 36 34 35 31 32 |t textsi ze 64512|
0020 20 75 73 65 20 5b 64 77-68 64 62 5d             | use [dw hdb]|

token.c:540:tds_process_tokens(0x329e160, 0x7fff3db37d64, 0x7fff3db37d60, 0x100)
util.c:156:Changed query state from PENDING to READING
net.c:555:Received header
0000 04 01 00 63 00 00 00 00-                        |...c....|

net.c:609:Received packet
0000 04 01 00 63 00 00 00 00-e5 4f 00 66 00 00 00 00 |...c.... .O.f....|
0010 0f 05 34 32 57 30 34 00-01 00 3a 00 53 51 4c 20 |..42W04. ..:.SQL |
0020 41 6e 79 77 68 65 72 65-20 45 72 72 6f 72 20 2d |Anywhere  Error -|
0030 31 33 31 3a 20 53 79 6e-74 61 78 20 65 72 72 6f |131: Syn tax erro|
0040 72 20 6e 65 61 72 20 27-75 73 65 27 20 6f 6e 20 |r near ' use' on |
0050 6c 69 6e 65 20 31 00 00-00 00 fd 02 00 01 00 00 |line 1.. ........|
0060 00 00 00               -                        |...|

token.c:555:processing result tokens.  marker is  e5(EED)
token.c:122:tds_process_default_tokens() marker is e5(EED)
token.c:2588:tds_process_msg() reading message 102 from server
token.c:2661:tds_process_msg() calling client msg handler
dbutil.c:85:_dblib_handle_info_message(0x32933f0, 0x329e160, 0x7fff3db37bb0)
dbutil.c:86:msgno 102: "SQL Anywhere Error -131: Syntax error near 'use' on line 1"
dblib.c:5780:dbgetuserdata(0x329d660)
dblib.c:5780:dbgetuserdata(0x329d660)
token.c:2674:tds_process_msg() returning TDS_SUCCEED
token.c:555:processing result tokens.  marker is  fd(DONE)
token.c:2339:tds_process_end: more_results = 0
		was_cancelled = 0
		error = 1
		done_count_valid = 0
token.c:2355:tds_process_end() state set to TDS_IDLE
util.c:156:Changed query state from READING to IDLE
token.c:2370:                rows_affected = 0
util.c:104:logic error: cannot change query state from IDLE to PENDING
token.c:540:tds_process_tokens(0x329e160, 0x7fff3db37d64, 0x7fff3db37d60, 0x100)
token.c:543:tds_process_tokens() state is COMPLETED
dblib.c:1443:dbclose(0x329d660)
dblib.c:258:dblib_del_connection(0x7ff3a4ad0660, 0x329e160)
mem.c:615:tds_free_all_results()
util.c:156:Changed query state from IDLE to DEAD
dblib.c:305:dblib_release_tds_ctx(1)
dblib.c:5882:dbfreebuf(0x329d660)
dblib.c:739:dbloginfree(0x329d490)
dblib.c:1512:dbexit(void)
dblib.c:305:dblib_release_tds_ctx(1)
 [2017-05-07 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2017-05-08 08:45 UTC] fuzzywy at 163 dot com
I can't change the stat, while still need feedback
 [2017-05-08 15:59 UTC] requinix@php.net
-Status: No Feedback +Status: Open
 [2017-05-15 08:23 UTC] adambaratz@php.net
Sorry for the delay in responding. I didn't get an email with your latest comment for some reason.

If you look in the trace, it says there's a syntax error coming from the use statement. I believe this results from the dbuse() call in pdo_dblib_handle_factory, but I don't think I don't think this issue could be coming from pdo_dblib. If you compare master to the 5.5.15 branch, you'll see that this function has changed very little since then.

My guess would've been that this is an issue with FreeTDS. I'm not sure what to make of the fact that you can otherwise connect to this server with FreeTDS. If you're able to get the log from that session, that might reveal what's going on.
 [2017-05-16 01:48 UTC] fuzzywy at 163 dot com
the session log connect with tsql
===========================
log.c:196:Starting log file for FreeTDS 0.91
        on 2017-05-16 09:23:39 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0x1e123b0, UTF-8)
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
iconv.c:394:tds_iconv_open: done
net.c:205:Connecting to 10.40.57.148 port 2640 (TDS version 5.0)
net.c:270:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:310:tds_open_socket() succeeded
util.c:156:Changed query state from DEAD to IDLE
net.c:741:Sending packet
0000 02 00 02 00 00 00 00 00-43 5a 31 38 36 00 00 00 |........ CZ186...|
0010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0020 00 00 00 00 00 00 05 64-63 62 6f 00 00 00 00 00 |.......d cbo.....|
0030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0040 00 00 00 00 00 04 64 63-62 6f 00 00 00 00 00 00 |......dc bo......|
0050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0060 00 00 00 00 04 34 34 38-35 30 00 00 00 00 00 00 |.....448 50......|
0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0080 00 00 00 05 03 01 06 0a-09 01 00 00 00 00 00 00 |........ ........|
0090 00 00 00 00 54 53 51 4c-00 00 00 00 00 00 00 00 |....TSQL ........|
00a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00b0 00 00 04 74 65 73 74 00-00 00 00 00 00 00 00 00 |...test. ........|
00c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00d0 00 04 00 04 64 63 62 6f-00 00 00 00 00 00 00 00 |....dcbo ........|
00e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00f0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0180 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0190 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01b0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01d0 00 06 05 00 00 00 54 44-53 2d 4c 69 62 72 61 72 |......TD S-Librar|
01e0 0a 05 00 00 00 00 0d 11-75 73 5f 65 6e 67 6c 69 |........ us_engli|
01f0 73 68 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |sh...... ........|

net.c:741:Sending packet
0000 02 01 00 61 00 00 00 00-00 00 00 00 00 00 0a 00 |...a.... ........|
0010 00 00 00 00 00 00 00 00-00 00 00 00 00 69 73 6f |........ .....iso|
0020 5f 31 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |_1...... ........|
0030 00 00 00 00 00 00 00 00-00 00 00 05 01 35 31 32 |........ .....512|
0040 00 00 00 03 00 00 00 00-e2 16 00 01 09 00 08 0e |........ ........|
0050 6d 7f ff ff ff fe 02 09-00 00 00 00 02 68 00 00 |m....... .....h..|
0060 00                     -                        |.|

token.c:328:tds_process_login_tokens()
net.c:555:Received header
0000 04 01 00 5a 00 00 00 00-                        |...Z....|

net.c:609:Received packet
0000 04 01 00 5a 00 00 00 00-e3 08 00 03 05 69 73 6f |...Z.... .....iso|
0010 5f 31 00 e3 09 00 04 03-35 31 32 03 35 31 32 ad |_1...... 512.512.|
0020 16 00 05 05 00 00 00 0c-53 51 4c 20 41 6e 79 77 |........ SQL Anyw|
0030 68 65 72 65 10 00 00 00-e2 16 00 01 09 00 08 0e |here.... ........|
0040 61 01 ff ff fe e6 02 09-07 fe 3f 9e e6 68 00 00 |a....... ..?..h..|
0050 0a fd 00 00 01 00 d5 56-17 00                   |.......V ..|

token.c:337:looking for login token, got  e3(ENVCHANGE)
token.c:122:tds_process_default_tokens() marker is e3(ENVCHANGE)
token.c:2493:server indicated charset change to "iso_1"
iconv.c:988:setting server single-byte charset to "ISO-8859-1"
token.c:337:looking for login token, got  e3(ENVCHANGE)
token.c:122:tds_process_default_tokens() marker is e3(ENVCHANGE)
token.c:2477:changing block size from 512 to 512
token.c:337:looking for login token, got  ad(LOGINACK)
token.c:373:server reports TDS version 5.0.0.0
token.c:375:Product name for 0x5000000 is unknown
token.c:337:looking for login token, got  e2(CAPABILITY)
token.c:122:tds_process_default_tokens() marker is e2(CAPABILITY)
token.c:337:looking for login token, got  fd(DONE)
token.c:122:tds_process_default_tokens() marker is fd(DONE)
token.c:2339:tds_process_end: more_results = 0
                was_cancelled = 0
                error = 0
                done_count_valid = 0
token.c:2355:tds_process_end() state set to TDS_IDLE
token.c:2370:                rows_affected = 1529557
token.c:438:tds_process_login_tokens() returning TDS_SUCCEED
mem.c:615:tds_free_all_results()
util.c:156:Changed query state from IDLE to QUERYING
util.c:156:Changed query state from QUERYING to PENDING
net.c:741:Sending packet
0000 0f 01 00 21 00 00 00 00-21 14 00 00 00 00 73 65 |...!.... !.....se|
0010 74 20 74 65 78 74 73 69-7a 65 20 36 34 35 31 32 |t textsi ze 64512|
0020 20                     -                        | |

token.c:540:tds_process_tokens(0x1e123b0, 0x7ffffda8e694, 0x7ffffda8e690, 0x100)
util.c:156:Changed query state from PENDING to READING
net.c:555:Received header
0000 04 01 00 11 00 00 00 00-                        |........|

net.c:609:Received packet
0000 04 01 00 11 00 00 00 00-fd 00 00 01 00 00 00 00 |........ ........|
0010 00                     -                        |.|

token.c:555:processing result tokens.  marker is  fd(DONE)
token.c:2339:tds_process_end: more_results = 0
                was_cancelled = 0
                error = 0
                done_count_valid = 0
token.c:2355:tds_process_end() state set to TDS_IDLE
util.c:156:Changed query state from READING to IDLE
token.c:2370:                rows_affected = 0
util.c:104:logic error: cannot change query state from IDLE to PENDING
token.c:540:tds_process_tokens(0x1e123b0, 0x7ffffda8e694, 0x7ffffda8e690, 0x100)
token.c:543:tds_process_tokens() state is COMPLETED
mem.c:615:tds_free_all_results()
util.c:156:Changed query state from IDLE to DEAD
 [2017-05-16 01:58 UTC] fuzzywy at 163 dot com
The log file which connect by pdo_dblib in php-5.5.15
================================
09:53:54.580743 14500 (log.c:196):Starting log file for FreeTDS 0.91
        on 2017-05-16 09:53:54 with debug flags 0xffff.
09:53:54.580768 14500 (iconv.c:330):tds_iconv_open(0x1e54100, UTF-8)
09:53:54.580783 14500 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
09:53:54.580787 14500 (iconv.c:187):local name for UTF-8 is UTF-8
09:53:54.580789 14500 (iconv.c:187):local name for UCS-2LE is UCS-2LE
09:53:54.580792 14500 (iconv.c:187):local name for UCS-2BE is UCS-2BE
09:53:54.580794 14500 (iconv.c:349):setting up conversions for client charset "UTF-8"
09:53:54.580798 14500 (iconv.c:351):preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
09:53:54.580801 14500 (iconv.c:391):preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
09:53:54.580804 14500 (iconv.c:394):tds_iconv_open: done
09:53:54.580811 14500 (net.c:205):Connecting to 10.40.57.148 port 2640 (TDS version 5.0)
09:53:54.580849 14500 (net.c:270):tds_open_socket: connect(2) returned "Operation now in progress"
09:53:54.583468 14500 (net.c:310):tds_open_socket() succeeded
09:53:54.583482 14500 (util.c:156):Changed query state from DEAD to IDLE
09:53:54.583489 14500 (net.c:741):Sending packet
0000 02 00 02 00 00 00 00 00-4d 61 73 74 65 72 00 00 |........ Master..|
0010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0020 00 00 00 00 00 00 06 64-63 62 6f 00 00 00 00 00 |.......d cbo.....|
0030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0040 00 00 00 00 00 04 64 63-62 6f 00 00 00 00 00 00 |......dc bo......|
0050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0060 00 00 00 00 04 31 34 35-30 30 00 00 00 00 00 00 |.....145 00......|
0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0080 00 00 00 05 03 01 06 0a-09 01 00 00 00 00 00 00 |........ ........|
0090 00 00 00 00 50 48 50 20-47 65 6e 65 72 69 63 20 |....PHP  Generic |
00a0 44 42 2d 6c 69 62 00 00-00 00 00 00 00 00 00 00 |DB-lib.. ........|
00b0 00 00 12 31 30 2e 34 30-2e 35 37 2e 31 34 38 3a |...10.40 .57.148:|
00c0 32 36 34 30 00 00 00 00-00 00 00 00 00 00 00 00 |2640.... ........|
00d0 00 11 00 04 64 63 62 6f-00 00 00 00 00 00 00 00 |....dcbo ........|
00e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00f0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0180 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0190 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01b0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01d0 00 06 05 00 00 00 44 42-2d 4c 69 62 72 61 72 79 |......DB -Library|
01e0 0a 05 00 00 00 00 0d 11-75 73 5f 65 6e 67 6c 69 |........ us_engli|
01f0 73 68 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |sh...... ........|

09:53:54.583568 14500 (net.c:741):Sending packet
0000 02 01 00 61 00 00 00 00-00 00 00 00 00 00 0a 00 |...a.... ........|
0010 00 00 00 00 00 00 00 00-00 00 00 00 00 75 74 66 |........ .....utf|
0020 38 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |8....... ........|
0030 00 00 00 00 00 00 00 00-00 00 00 04 01 35 31 32 |........ .....512|
0040 00 00 00 03 00 00 00 00-e2 16 00 01 09 00 08 0e |........ ........|
0050 6d 7f ff ff ff fe 02 09-00 00 00 00 02 68 00 00 |m....... .....h..|
0060 00                     -                        |.|

09:53:54.583591 14500 (token.c:328):tds_process_login_tokens()
09:53:54.589622 14500 (net.c:555):Received header
0000 04 01 00 59 00 00 00 00-                        |...Y....|

09:53:54.589637 14500 (net.c:609):Received packet
0000 04 01 00 59 00 00 00 00-e3 07 00 03 04 75 74 66 |...Y.... .....utf|
0010 38 00 e3 09 00 04 03 35-31 32 03 35 31 32 ad 16 |8......5 12.512..|
0020 00 05 05 00 00 00 0c 53-51 4c 20 41 6e 79 77 68 |.......S QL Anywh|
0030 65 72 65 10 00 00 00 e2-16 00 01 09 00 08 0e 61 |ere..... .......a|
0040 01 ff ff fe e6 02 09 07-fe 3f 9e e6 68 00 00 0a |........ .?..h...|
0050 fd 00 00 01 00 e0 59 17-00                      |......Y. .|

09:53:54.630485 14500 (token.c:337):looking for login token, got  e3(ENVCHANGE)
09:53:54.630497 14500 (token.c:122):tds_process_default_tokens() marker is e3(ENVCHANGE)
09:53:54.630508 14500 (token.c:2493):server indicated charset change to "utf8"
09:53:54.630517 14500 (iconv.c:988):setting server single-byte charset to "UTF-8"
09:53:54.630524 14500 (dblib.c:327):db_env_chg(0x1e54100, 3, , utf8)
09:53:54.630529 14500 (token.c:337):looking for login token, got  e3(ENVCHANGE)
09:53:54.630534 14500 (token.c:122):tds_process_default_tokens() marker is e3(ENVCHANGE)
09:53:54.630538 14500 (token.c:2477):changing block size from 512 to 512
09:53:54.630542 14500 (dblib.c:327):db_env_chg(0x1e54100, 4, 512, 512)
09:53:54.630547 14500 (token.c:337):looking for login token, got  ad(LOGINACK)
09:53:54.630551 14500 (token.c:373):server reports TDS version 5.0.0.0
09:53:54.630555 14500 (token.c:375):Product name for 0x5000000 is unknown
09:53:54.630559 14500 (token.c:337):looking for login token, got  e2(CAPABILITY)
09:53:54.630564 14500 (token.c:122):tds_process_default_tokens() marker is e2(CAPABILITY)
09:53:54.630568 14500 (token.c:337):looking for login token, got  fd(DONE)
09:53:54.630573 14500 (token.c:122):tds_process_default_tokens() marker is fd(DONE)
09:53:54.630579 14500 (token.c:2339):tds_process_end: more_results = 0
                was_cancelled = 0
                error = 0
                done_count_valid = 0
09:53:54.630583 14500 (token.c:2355):tds_process_end() state set to TDS_IDLE
09:53:54.630587 14500 (token.c:2370):                rows_affected = 1530336
09:53:54.630591 14500 (token.c:438):tds_process_login_tokens() returning TDS_SUCCEED
09:53:54.630600 14500 (mem.c:615):tds_free_all_results()
09:53:54.630605 14500 (util.c:156):Changed query state from IDLE to QUERYING
09:53:54.630609 14500 (util.c:156):Changed query state from QUERYING to PENDING
09:53:54.630614 14500 (net.c:741):Sending packet
0000 0f 01 00 21 00 00 00 00-21 14 00 00 00 00 73 65 |...!.... !.....se|
0010 74 20 74 65 78 74 73 69-7a 65 20 36 34 35 31 32 |t textsi ze 64512|
0020 20                     -                        | |

09:53:54.630639 14500 (token.c:540):tds_process_tokens(0x1e54100, 0x7ffc5a301844, 0x7ffc5a301840, 0x100)
09:53:54.630645 14500 (util.c:156):Changed query state from PENDING to READING
09:53:54.646789 14500 (net.c:555):Received header
0000 04 01 00 11 00 00 00 00-                        |........|

09:53:54.646802 14500 (net.c:609):Received packet
0000 04 01 00 11 00 00 00 00-fd 00 00 01 00 00 00 00 |........ ........|
0010 00                     -                        |.|

09:53:54.646814 14500 (token.c:555):processing result tokens.  marker is  fd(DONE)
09:53:54.646819 14500 (token.c:2339):tds_process_end: more_results = 0
                was_cancelled = 0
                error = 0
                done_count_valid = 0
09:53:54.646824 14500 (token.c:2355):tds_process_end() state set to TDS_IDLE
09:53:54.646828 14500 (util.c:156):Changed query state from READING to IDLE
09:53:54.646832 14500 (token.c:2370):                rows_affected = 0
09:53:54.646836 14500 (util.c:104):logic error: cannot change query state from IDLE to PENDING
09:53:54.646840 14500 (token.c:540):tds_process_tokens(0x1e54100, 0x7ffc5a301844, 0x7ffc5a301840, 0x100)
09:53:54.646845 14500 (token.c:543):tds_process_tokens() state is COMPLETED
09:53:54.646850 14500 (dblib.c:239):dblib_add_connection(0x7fed67e43660, 0x1e54100)
09:53:54.646856 14500 (dblib.c:1398):dbuse(0x1e535c0, dwhdb)
09:53:54.646861 14500 (dblib.c:1312):dbcmd(0x1e535c0, use [dwhdb])
09:53:54.646870 14500 (dblib.c:1319):dbcmd() bufsz = 0
09:53:54.646879 14500 (dblib.c:1369):dbsqlexec(0x1e535c0)
09:53:54.646884 14500 (dblib.c:6862):dbsqlsend(0x1e535c0)
09:53:54.646889 14500 (mem.c:615):tds_free_all_results()
09:53:54.646893 14500 (util.c:156):Changed query state from IDLE to QUERYING
09:53:54.646897 14500 (util.c:156):Changed query state from QUERYING to PENDING
09:53:54.646901 14500 (net.c:741):Sending packet
0000 0f 01 00 19 00 00 00 00-21 0c 00 00 00 00 75 73 |........ !.....us|
0010 65 20 5b 64 77 68 64 62-5d                      |e [dwhdb ]|

09:53:54.646922 14500 (dblib.c:4639):dbsqlok(0x1e535c0)
09:53:54.646927 14500 (dblib.c:4669):dbsqlok() not done, calling tds_process_tokens()
09:53:54.646931 14500 (token.c:540):tds_process_tokens(0x1e54100, 0x7ffc5a301cbc, 0x7ffc5a301cb8, 0x6914)
09:53:54.646936 14500 (util.c:156):Changed query state from PENDING to READING
09:53:54.655803 14500 (net.c:555):Received header
0000 04 01 00 11 00 00 00 00-                        |........|

09:53:54.655816 14500 (net.c:609):Received packet
0000 04 01 00 11 00 00 00 00-fd 00 00 01 00 00 00 00 |........ ........|
0010 00                     -                        |.|

09:53:54.655826 14500 (token.c:555):processing result tokens.  marker is  fd(DONE)
09:53:54.655830 14500 (token.c:2339):tds_process_end: more_results = 0
                was_cancelled = 0
                error = 0
                done_count_valid = 0
09:53:54.655835 14500 (token.c:2355):tds_process_end() state set to TDS_IDLE
09:53:54.655839 14500 (util.c:156):Changed query state from READING to IDLE
09:53:54.655843 14500 (token.c:2370):                rows_affected = 0
09:53:54.655847 14500 (util.c:104):logic error: cannot change query state from IDLE to PENDING
09:53:54.655853 14500 (dblib.c:4707):dbsqlok() end status is SUCCEED
09:53:54.655857 14500 (dblib.c:4718):dbsqlok() end status was success
09:53:54.655863 14500 (dblib.c:1668):dbresults(0x1e535c0)
09:53:54.655867 14500 (dblib.c:1674):dbresults: dbresults_state is 5 (_DB_RES_SUCCEED)
09:53:54.655871 14500 (dblib.c:1657):dbresults returning 1 (SUCCEED)
09:53:54.655876 14500 (dblib.c:5854):dbcanquery(0x1e535c0)
09:53:54.655880 14500 (token.c:540):tds_process_tokens(0x1e54100, 0x7ffc5a301cdc, (nil), 0x108)
09:53:54.656060 14500 (token.c:543):tds_process_tokens() state is COMPLETED
09:53:54.656070 14500 (dblib.c:1443):dbclose(0x1e535c0)
09:53:54.656074 14500 (dblib.c:258):dblib_del_connection(0x7fed67e43660, 0x1e54100)
09:53:54.656079 14500 (mem.c:615):tds_free_all_results()
09:53:54.656097 14500 (util.c:156):Changed query state from IDLE to DEAD
09:53:54.656104 14500 (dblib.c:305):dblib_release_tds_ctx(1)
09:53:54.656112 14500 (dblib.c:5882):dbfreebuf(0x1e535c0)
09:53:54.656117 14500 (dblib.c:739):dbloginfree(0x1e53410)
09:53:54.656720 14500 (dblib.c:1512):dbexit(void)
09:53:54.656995 14500 (dblib.c:1512):dbexit(void)
09:53:54.657007 14500 (dblib.c:305):dblib_release_tds_ctx(1)
 [2017-05-16 11:29 UTC] adambaratz@php.net
It's hard to say what's going on here. Very little has changed in pdo_dblib between 5.5 and 7.1. That said, there are differences in the logs.

This happens in 5.5:
09:53:54.630614 14500 (net.c:741):Sending packet
0000 0f 01 00 21 00 00 00 00-21 14 00 00 00 00 73 65 |...!.... !.....se|
0010 74 20 74 65 78 74 73 69-7a 65 20 36 34 35 31 32 |t textsi ze 64512|
0020 20                     -                        | |


This happens in 7.1:
net.c:741:Sending packet
0000 0f 01 00 2c 00 00 00 00-21 1f 00 00 00 00 73 65 |...,.... !.....se|
0010 74 20 74 65 78 74 73 69-7a 65 20 36 34 35 31 32 |t textsi ze 64512|
0020 20 75 73 65 20 5b 64 77-68 64 62 5d             | use [dw hdb]|

After that packet is the error that results in the PDO exception. I see two differences: two ! (instead of , and !), invoking USE right after the SET. In 5.5, USE is invoked earlier.

My guess is that there was some build difference that's causing the connection to be made differently. You could double-check your PHP build settings and see if anything stands out. Another thing you could try would be upgrading to FreeTDS 1.0. Newer versions have a slightly different way of selecting the database:
https://github.com/php/php-src/blob/PHP-7.1.4/ext/pdo_dblib/dblib_driver.c#L415

Maybe that would cause this issue to go away.

I'm not sure what other help I can offer. I don't have access to a Sybase server, so it's difficult to do any testing of my own. Sorry you're having this problem with pdo_dblib. I realize this must be a frustrating thing to have to deal with on your end.
 [2017-05-23 15:18 UTC] adambaratz@php.net
-Status: Open +Status: Not a bug
 [2017-05-23 15:18 UTC] adambaratz@php.net
Closing as this doesn't appear to be related to pdo_dblib.
 [2018-02-02 03:10 UTC] fuzzywy at 163 dot com
I finally resolved the case by replace dbname to dbName in pdo_dblib dsn.

Howerver,the manual's still dbname.
http://php.net/manual/zh/ref.pdo-dblib.connection.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC