diff options
author | Nikita Popov <nikic@php.net> | 2015-04-04 15:58:00 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2015-04-04 16:00:17 +0200 |
commit | 30d59aed1c5a27435149c0609ad8a66802df117d (patch) | |
tree | 7a67402bd42acf51be9ccc0ad5838a4ca64cdd48 | |
parent | f3e3d85bb2dec908f348e470f64bd99001345998 (diff) | |
download | php-git-30d59aed1c5a27435149c0609ad8a66802df117d.tar.gz |
Try fixing PDO MySQL pconnect test
Use less aggressive conversion to exceptions, in particular
do not convert warnings that happen during check_liveness. If the
server has gone away this will just reconnect and we still end up
with a valid connection, so it shouldn't throw.
Also drop some unnecessary checks for malloc returning NULL.
-rw-r--r-- | ext/pdo/pdo_dbh.c | 17 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt | 3 |
2 files changed, 7 insertions, 13 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 41d3974b72..47cba0edb9 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -216,6 +216,7 @@ static PHP_METHOD(PDO, dbh_constructor) zend_restore_error_handling(&zeh); return; } + zend_restore_error_handling(&zeh); /* parse the data source name */ colon = strchr(data_source, ':'); @@ -226,7 +227,6 @@ static PHP_METHOD(PDO, dbh_constructor) snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source); if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) { - zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name"); return; } @@ -235,7 +235,6 @@ static PHP_METHOD(PDO, dbh_constructor) colon = strchr(data_source, ':'); if (!colon) { - zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI: %s)", alt_dsn); return; } @@ -245,13 +244,11 @@ static PHP_METHOD(PDO, dbh_constructor) /* the specified URI holds connection details */ data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn)); if (!data_source) { - zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI"); return; } colon = strchr(data_source, ':'); if (!colon) { - zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)"); return; } @@ -262,7 +259,6 @@ static PHP_METHOD(PDO, dbh_constructor) if (!driver) { /* NB: don't want to include the data_source in the error message as * it might contain a password */ - zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver"); return; } @@ -317,15 +313,8 @@ static PHP_METHOD(PDO, dbh_constructor) /* need a brand new pdbh */ pdbh = pecalloc(1, sizeof(*pdbh), 1); - if (!pdbh) { - php_error_docref(NULL, E_ERROR, "out of memory while allocating PDO handle"); - /* NOTREACHED */ - } - pdbh->is_persistent = 1; - if (!(pdbh->persistent_id = pemalloc(plen + 1, 1))) { - php_error_docref(NULL, E_ERROR, "out of memory while allocating PDO handle"); - } + pdbh->persistent_id = pemalloc(plen + 1, 1); memcpy((char *)pdbh->persistent_id, hashkey, plen+1); pdbh->persistent_id_len = plen; pdbh->def_stmt_ce = dbh->def_stmt_ce; @@ -363,6 +352,8 @@ static PHP_METHOD(PDO, dbh_constructor) goto options; } + zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh); + if (driver->db_handle_factory(dbh, options)) { /* all set */ diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt index 87a69125bb..d5dd3e67f9 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt @@ -68,6 +68,9 @@ MySQLPDOTest::skip(); print "done!"; ?> --EXPECTF-- +Warning: PDO::__construct(file:/tmp/pdomuri.tst): failed to open stream: No such file or directory in %s on line %d [002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI + +Warning: PDO::__construct(file:/tmp/pdomuri.tst): failed to open stream: No such file or directory in %s on line %d [003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI done! |