Bug #80587 [Opn->Fbk]: PDO driver instance shared between different PDO objects

From: Date: Sun, 10 Jan 2021 21:52:45 +0000
Subject: Bug #80587 [Opn->Fbk]: PDO driver instance shared between different PDO objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231481@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80587&edit=1 ID: 80587 Updated by: adambaratz@php.net Reported by: jeremys at ha dot com Summary: PDO driver instance shared between different PDO objects -Status: Open +Status: Feedback Type: Bug Package: PDO related Operating System: RHEL 7.8 PHP Version: 7.3.25 Block user comment: N Private report: N New Comment: I left a comment on the timeout issue on #80586. Just to make sure I'm following the more general problem you're describing, could you give an example that uses a different option and describe the behavior you'd expect to see? One thing to point out with the timeout options is that no matter how pdo_dblib calls dbsetlogintime or dbsettime, the timeouts will apply to all PDO instances. Note that those functions don't take any kind of driver handle, just a timeout value. Previous Comments: ------------------------------------------------------------------------ [2021-01-04 15:47:02] jeremys at ha dot com Description: ------------ When instantiating a new PDO object with a specific driver (PDO_DBLIB in this example), the driver settings that were used from the first PDO object are maintained across further PDO objects, post-garbage collection. In my specific example, I'm using FreeTDS with a query timeout of 300 seconds ("timeout = 300" in freetds.conf). Theoretically, each new PDO instance using dblib as the driver should default to the 300 second query timeout unless specified otherwise, such as via the $options parameter in PDO::__construct(). In the test script, the first PDO object is created with a connection timeout of 5 seconds, overriding FreeTDS's configured 300 seconds. After releasing the first object, a 2nd PDO object is created without specifying any driver options ($options parameter in PDO::__construct() is null), meaning the default of 300 seconds should be used. Instead, the value of the first PDO object using dblib is used. This applies to all options, but the timeout is the easiest example to test. This prevents effectively using custom driver options. Note the different hostnames in the test script. Appears to happen in PHP 8 as well based on the PDO source code. Test script: --------------- <?php // 5 second timeout overrides freetds.conf $pdo = new PDO( 'dblib:dbname=northwinds;host=contoso', 'username', 'password', [ PDO::ATTR_TIMEOUT => 5 ] ); try { $pdo->query( "WAITFOR DELAY '00:00:10'" ); var_dump( $pdo->query( "SELECT 'output' AS Output" )->fetch()['Output'] ); } catch( Throwable $e ) { var_dump( stripos( $pdo->errorInfo()[2], 'DBPROCESS is dead or not enabled' ) === 0 ); } $pdo = null; // no $options defined, timeout should be 300 seconds; hostname is different $pdo = new PDO( 'dblib:dbname=northwinds;host=contoso2', 'username', 'password' ); try { $pdo->query( "WAITFOR DELAY '00:00:10'" ); var_dump( $pdo->query( "SELECT 'output' AS Output" )->fetch()['Output'] ); } catch( Throwable $e ) { var_dump( stripos( $pdo->errorInfo()[2], 'DBPROCESS is dead or not enabled' ) === 0 ); } Expected result: ---------------- bool(true) string(6) "output" Actual result: -------------- bool(true) bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80587&edit=1

« previous php.bugs (#231481) next »