php / doc-en

English PHP documentation
482 stars 722 forks source link

PDO::getAttribute() does not support PDO::ATTR_TIMEOUT #2034

Open shyim opened 1 year ago

shyim commented 1 year ago

Description

The following code:

<?php

$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(\PDO::ATTR_TIMEOUT, 5);

var_dump($pdo->getAttribute(\PDO::ATTR_TIMEOUT));

It seems like not covered by https://github.com/php/php-src/blob/master/ext/pdo_mysql/mysql_driver.c#L490

Resulted in this output:

Fatal error: Uncaught PDOException: SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute

But I expected this output instead:

int(5)

PHP Version

PH P 8.1.12

Operating System

macOS Ventura 13.1 Beta 2

cmb69 commented 1 year ago

As is, for PDO_MySQL this is a connection attribute, so setting it after the the PDO instance has been constructed, won't change anything. Still, it should be possible to retrieve the timeout, I guess.

cmb69 commented 1 year ago

Well, apparently none of the other bundled PDO drivers supports getting the value of PDO::ATTR_TIMEOUT either, so I think we should leave it as this, but document it (currently, PDO::ATTR_TIMEOUT is explicitly listed as $attribute for PDO::getAttribute()).