Bug #49344 [Com]: pdo_mssql fails to connect,throws PDOException SQLSTATE[] (null) (severity 0)

From: Date: Mon, 11 Apr 2011 16:47:33 +0000
Subject: Bug #49344 [Com]: pdo_mssql fails to connect,throws PDOException SQLSTATE[] (null) (severity 0)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-160102@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=49344&edit=1

 ID:                 49344
 Comment by:         tom at punkave dot com
 Reported by:        rockyjl at gmai dot com
 Summary:            pdo_mssql fails to connect,throws PDOException
                     SQLSTATE[] (null) (severity 0)
 Status:             No Feedback
 Type:               Bug
 Package:            PDO related
 Operating System:   win2003 X64
 PHP Version:        5.2.11RC1
 Assigned To:        felipe
 Block user comment: N
 Private report:     N

 New Comment:

Still experiencing this error. Tweaking freetds.conf:


[global]
        # TDS protocol version
# Microsoft compatible we hope
tds version = 7.0


Had no effect.

PHP 5.3.5 (cli) (built: Jan 27 2011 11:42:56)  on macports.


Previous Comments:
------------------------------------------------------------------------
[2011-01-07 09:37:47] wrobel at wsb-nlu dot edu dot pl

It seems that the problem is solved by changing tds version to 7.0
instead of 8.0 in freetds configuration...

------------------------------------------------------------------------
[2011-01-06 12:11:45] wrobel at wsb-nlu dot edu dot pl

I have the same problem when connecting: PDOException with message
SQLSTATE[] (null) (severity 0).

My environment is:
PHP 5.2.14
apache-2.2.16
Sql Server 2008 Express (and Sql Server 2008 R2)
Linux/PLD

------------------------------------------------------------------------
[2009-10-09 18:56:19] svn@php.net

Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=289440
Log: -  Possible fix for bug #49344 on Windows (pdo_mssql fails to
connect,throws PDOException SQLSTATE[] (null) (severity 0))

------------------------------------------------------------------------
[2009-10-07 09:14:41] philipp at servicemail24 dot de

The same error occurs using Ubuntu 0910 with Zend Framework:

    require_once('Zend/Db.php');

    $db = Zend_Db::factory('Pdo_Mssql', array(
      'host'     => 'sqlsrv',
      'username' => 'php',
      'password' => 'secret',
      'dbname'   => 'myDatabase',
      'pdoType'  => 'dblib'
    ));
    $result = $db->fetchAll(SELECT * FROM MyTable");
    var_dump($result);


Zend_Db_Adapter_Exception: SQLSTATE[] (null) (severity 0) in
/usr/share/php/libzend-framework-php/Zend/Db/Adapter/Pdo/Abstract.php on
line 144

------------------------------------------------------------------------
[2009-09-23 04:20:01] Rockyjl at gmail dot com

My Modification:

static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options
TSRMLS_DC)
{
	pdo_dblib_db_handle *H;
	int i, ret = 0;
	char *location = " L=";
	struct pdo_data_src_parser vars[] = {
		{ "charset",	NULL,	0 },
		{ "appname",	"PHP " PDO_DBLIB_FLAVOUR,	0 },
		{ "host",		"127.0.0.1", 0 },
		{ "dbname",		NULL,	0 },
		{ "secure",		NULL,	0 }, /* DBSETLSECURE */
		/* TODO: DBSETLVERSION ? */
	};

	php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars,
5);

	H = pecalloc(1, sizeof(*H), dbh->is_persistent);
	H->login = dblogin();
	H->err.sqlstate = dbh->error_code;

	if (!H->login) {
		strcat(location, "login");
		goto cleanup;
	}

	if (dbh->username) {
		DBSETLUSER(H->login, dbh->username);
	}
	if (dbh->password) {
		DBSETLPWD(H->login, dbh->password);
	}
	
#if !PHP_DBLIB_IS_MSSQL
	if (vars[0].optval) {
		DBSETLCHARSET(H->login, vars[0].optval);
	}
#endif

	DBSETLAPP(H->login, vars[1].optval);

#if PHP_DBLIB_IS_MSSQL
	dbprocerrhandle(H->login, (EHANDLEFUNC) error_handler);
	dbprocmsghandle(H->login, (MHANDLEFUNC) msg_handler);
#endif

	H->link = dbopen(H->login, vars[2].optval);

	if (H->link == NULL) {
		strcat(location, "link");
		goto cleanup;
	}

	/* dblib do not return more than this length from text/image */
	DBSETOPT(H->link, DBTEXTLIMIT, "2147483647");
	
	/* limit text/image from network */
	DBSETOPT(H->link, DBTEXTSIZE, "2147483647");

	if (vars[3].optval && FAIL == dbuse(H->link, vars[3].optval)) {
		strcat(location, "optval");
		goto cleanup;
	}

	ret = 1;
	dbh->max_escaped_char_length = 2;
	dbh->alloc_own_columns = 1;

cleanup:
	for (i = 0; i < sizeof(vars)/sizeof(vars[0]); i++) {
		if (vars[i].freeme) {
			efree(vars[i].optval);
		}
	}

	dbh->methods = &dblib_methods;
	dbh->driver_data = H;

	if (!ret) {
		zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC,
			"SQLSTATE[%s] %s (severity %d) %s",  //I want to findout the bug
location !
			DBLIB_G(err).sqlstate,
			DBLIB_G(err).dberrstr,
			DBLIB_G(err).severity,
			location);
	}

	return ret;
}

The PDO MSSQL work is correct, the bug never happen and never throws any
PDOException after Complie php_pdo_mssql.dll ...

I think my modification STOP all PDOException throw ...

Anyone can tell me what is the problem ?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=49344


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=49344&edit=1


Thread (17 messages)

« previous php.bugs (#160102) next »