Bug #80587 [NEW]: PDO driver instance shared between different PDO objects
| From: | jeremys at ha dot com | Date: | Mon, 04 Jan 2021 15:47:02 +0000 |
| Subject: | Bug #80587 [NEW]: PDO driver instance shared between different PDO objects | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-231361@lists.php.net to get a copy of this message | ||
From: jeremys at ha dot com
Operating system: RHEL 7.8
PHP version: 7.3.25
Package: PDO related
Bug Type: Bug
Bug description:PDO driver instance shared between different PDO objects
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 bug report at https://bugs.php.net/bug.php?id=80587&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80587&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80587&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80587&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80587&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80587&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80587&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80587&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80587&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80587&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80587&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80587&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80587&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80587&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80587&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80587&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80587&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80587&r=mysqlcfg