| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [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}
Patchesmssql-null-exception (last revision 2013-09-25 14:55 UTC by kaplan@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 12:00:01 2025 UTC | 
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;