Edit report at https://bugs.php.net/bug.php?id=58863&edit=1
ID: 58863 Updated by: m...@php.net Reported by: marion dot jeff at gmail dot com Summary: Reconnect support broken -Status: Open +Status: Wont fix Type: Bug -Package: PDO_MYSQL +Package: *General Issues Operating System: *nix (Centos 4/5, Arch) PHP Version: 5.2.8 Block user comment: N Private report: N New Comment: PECL PDO packages are obsolete. Previous Comments: ------------------------------------------------------------------------ [2011-07-01 05:24:55] sinomad123 at gmail dot com I've got the same problem,too. PDO class does not have a reconnect function.When reading the source, I found the broken code. So I have to make some change as below: mysql_driver.c: ------------- 594 (added) long reconnect = pdo_attr_bval(driver_options, PDO_MYSQL_ATTR_RECONNECT, 0 TSRMLS_CC); 595 639 //#ifdef MYSQL_OPT_RECONNECT 640 /* since 5.0.3, the default for this option is 0 if not specified. 641 * we want the old behaviour */ 642 if( reconnect ){ 643 long reconnect = 1; 644 mysql_options(H->server, MYSQL_OPT_RECONNECT, (const char*)&reconnect); 645 } 646 //#endif php_pdo_mysql_int.h ------------------- 159 PDO_MYSQL_ATTR_INIT_COMMAND, (added) MYSQL_OPT_RECONNECT, pdo_mysql.c ----------- 72 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (long)PDO_MYSQL_ATTR_INIT_COMMAND); (added) REGISTER_PDO_CLASS_CONST_LONG("MYSQL_OPT_RECONNECT", (long)PDO_MYSQL_OPT_RECONNECT); implemention of function pdo_attr_bval:(in pdo/php_pdo_driver.h) -------------- static inline long pdo_attr_bval(zval *options, enum pdo_attribute_type option_name, long defval TSRMLS_DC) { zval **v; if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) { convert_to_boolean_ex(v); return Z_BVAL_PP(v); } return defval; } after make&install, you can use pdo_options to set MYSQL_OPT_RECONNECT: $conn = new PDO('mysql:host=xxx', 'xx', 'xx',array(PDO::MYSQL_OPT_RECONNECT=>true)); hope this will help. ------------------------------------------------------------------------ [2011-06-05 04:02:50] marion dot jeff at gmail dot com Reopening as there hasn't been any follow-up or comment. ------------------------------------------------------------------------ [2011-05-30 17:31:10] marion dot jeff at gmail dot com Johannes, If the current PDO stance on the issue is that you don't want to allow for even an optional enablement of the underlying MySQL OPT_RECONNECT behavior that's your prerogative. However, it seems the exact opposite decision was made in the past by the PDO_MYSQL maintainers when they chose to add code which explicitly enabled auto-reconnect behavior in the driver following the MySQL 5.0.3 change to the OPT_RECONNECT default. The existence of that code is the basis for this bug. That code is in fact broken. Lines 639-646 in the PHP 5.4 branch are not just dead code which is impossible to ever reach but both the code and comment are very misleading. Additionally there is another block up code (633-638) which makes the same mistake of trying to ifdef based on one of the MYSQL_OPT_ enums, which are not available to the preprocessor and so will always fail to match. If the project has changed it's mind about the reconnect behavior and wants it to be intentionally off that is fine by me but please fix the code so it represents this decision and ideally add some documentation about the behavior change that occurred. Feel free to contact me off list to discuss. ------------------------------------------------------------------------ [2011-05-26 08:27:24] johannes at schlueters dot de Doing a magic reconnect without notice to the user is bad as the connection looses its state (prepared statements become invalid, session variables are lost, temporary tables go away, ...) A manual reconnect also won't be implemented as MySQL specific feature. Please report it at bugs.php.net as general PDO request if you think this is really think this is useful. ------------------------------------------------------------------------ [2011-01-13 20:47:57] datib...@php.net Just came across this ticket when I realized that PDO doesn't have a reconnect method and assumed it was done "magically"; so I was surprised that this still doesn't work in 5.3.4 It would be really nice if this behaviour could be governed via a PDO:: parameter, specifically for MySQL or otherwise. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=58863 -- Edit this bug report at https://bugs.php.net/bug.php?id=58863&edit=1