php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48539 pdo_dblib fails to connect, throws empty PDOException "SQLSTATE[] (null)"
Submitted: 2009-06-12 19:59 UTC Modified: 2013-09-26 05:12 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:0 (0.0%)
From: frase at cs dot wisc dot edu Assigned: felipe (profile)
Status: Closed Package: PDO related
PHP Version: 5.2.10, 5.3.0RC4 OS: *
Private report: No CVE-ID: None
 [2009-06-12 19:59 UTC] frase at cs dot wisc dot edu
Description:
------------
I have compiled PHP 5.3.0RC3 from source as a module for Apache 2.2.11, and I cannot open a connection to an MSSQL server using PDO's dblib (FreeTDS) driver.  Instead, I get a PDOException with no SQLSTATE code or message.

The sample code below works in PHP 5.2.6 (as packaged for Jaunty).

Non-PDO MSSQL connections work ("mssql_connect()").

PDO MySQL connections also work ("PDO('mysql:...')").

"phpinfo()" confirms that the PDO extension is loaded, with dblib and mysql drivers.  The pdo_dblib section confirms that it is using FreeTDS.

There is no change by compiling the extensions (mssql, pdo, pdo_dblib) as external shared modules or built-in to libphp5.so.


Reproduce code:
---------------
<?php
header('Content-type: text/plain');

try {
	$db = new PDO('dblib:host=myhost;dbname=mydb', 'myuser', 'mypass') or die("failed to connect");
	$result = $db->query('select count(1) from mytable') or die ("failed to query database");
	echo "got ".($result->fetchColumn())." rows\n";
	$result->closeCursor() or die("failed to free resultset");
	$db = null;
} catch (Exception $e) {
	echo $e;
}


Expected result:
----------------
got (some-number) rows

Actual result:
--------------
exception 'PDOException' with message 'SQLSTATE[] (null) (severity 0)' in /home/user/htdocs/test-pdo.php:5
Stack trace:
#0 /home/user/htdocs/test-pdo.php(5): PDO->__construct('dblib:host=myho...', 'myuser', 'mypass')
#1 {main}

Patches

mssql-null-exception (last revision 2013-09-25 14:55 UTC by kaplan@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-19 13:40 UTC] frase at cs dot wisc dot edu
This problem remains in RC4.
 [2009-06-19 16:58 UTC] thomas dot parrott at jellyfish dot co dot uk
This issue appears to be in 5.2.10 as well.
 [2009-06-25 16:57 UTC] nicholas dot j dot miller at gmail dot com
Our development team is seeing this problem in 5.2.10 as well.
 [2009-06-27 21:43 UTC] tilo at levante dot de
The following patch solved the issue in version 5.2.10
These three lines were added from version 5.2.9 to 5.2.10.

I use a ms sql 7 server, maybe this server is not able th set the TEXTLIMIT to the given value.

Greetings

tilo


--- ext/pdo_dblib/dblib_driver.c.orig	2009-03-20 23:14:17.000000000 +0100
+++ ext/pdo_dblib/dblib_driver.c	2009-06-28 01:50:50.000000000 +0200
@@ -230,9 +230,9 @@
 		goto cleanup;
 	}
 
-	if (DBSETOPT(H->link, DBTEXTLIMIT, "2147483647") == FAIL) {
-		goto cleanup;
-	}
+//	if (DBSETOPT(H->link, DBTEXTLIMIT, "2147483647") == FAIL) {
+//		goto cleanup;
+//	}
 
 	if (vars[3].optval && FAIL == dbuse(H->link, vars[3].optval)) {
 		goto cleanup;
 [2009-06-28 02:10 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2 and HEAD.
5.3 in soon.

Thanks.
 [2011-04-11 18:37 UTC] tom at punkave dot com
Did this fix ever get put in PHP 5.3? I am getting this error exactly as 
originally described with all PHP 5.3.x versions tried.
 [2012-07-13 13:10 UTC] snowcorenet at gmail dot com
Could anyone tell me, please, if this is fixed in php 5.3?
 [2012-12-13 16:08 UTC] wdmeldon at gmail dot com
I've tested this in 5.3.19 and was not able to replicate.
 [2013-05-09 10:15 UTC] talktome at aboutandrew dot co dot uk
This problem exists in php 5.4.10
 [2013-09-25 14:55 UTC] kaplan@php.net
The following patch has been added/updated:

Patch Name: mssql-null-exception
Revision:   1380120958
URL:        https://bugs.php.net/patch-display.php?bug=48539&patch=mssql-null-exception&revision=1380120958
 [2013-09-26 05:12 UTC] ssufficool@php.net
I see that this option is not implemented in FreeTDS dblib.c. Calling DBSETOPT 
with this option should have no effect and produce no error. Masking it for all 
libraries except MS DBLIB (depreciated) is not a solution unless the underlying 
FreeTDS library has a bug.

The previous implementation would return exit if DBSETOPT failed, causing the 
connection to close with an error. The current version does not exit in error if 
the DBSETOPT returns FAIL.

Newer versions should return a more specific error than the "SQLSTATE[] (null) 
(severity 0)". Please test again and provide the error if you can. I am running 
Sybase ASE and so cannot accurately reproduce your error with MSSQL.
 [2013-09-27 02:54 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ac05cfb49912dd87264573df930d0ead3c3e0cca
Log: FIX BUG #48539 - Disable TEXTLIMIT for FreeTDS driver
 [2013-09-27 03:19 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ac05cfb49912dd87264573df930d0ead3c3e0cca
Log: FIX BUG #48539 - Disable TEXTLIMIT for FreeTDS driver
 [2013-09-27 09:14 UTC] derick@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ac05cfb49912dd87264573df930d0ead3c3e0cca
Log: FIX BUG #48539 - Disable TEXTLIMIT for FreeTDS driver
 [2014-10-07 23:17 UTC] stas@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ac05cfb49912dd87264573df930d0ead3c3e0cca
Log: FIX BUG #48539 - Disable TEXTLIMIT for FreeTDS driver
 [2014-10-07 23:28 UTC] stas@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ac05cfb49912dd87264573df930d0ead3c3e0cca
Log: FIX BUG #48539 - Disable TEXTLIMIT for FreeTDS driver
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC