|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-01-10 21:52 UTC] adambaratz@php.net
-Status: Open
+Status: Feedback
[2021-01-10 21:52 UTC] adambaratz@php.net
[2021-01-11 14:38 UTC] jeremys at ha dot com
-Status: Feedback
+Status: Open
[2021-01-11 14:38 UTC] jeremys at ha dot com
[2021-09-27 11:41 UTC] cmb@php.net
-Package: PDO related
+Package: PDO DBlib
[2021-09-27 11:41 UTC] cmb@php.net
[2023-05-26 10:04 UTC] raymondhickss33030 at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 08:00:01 2025 UTC |
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)