diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 3ff03e54b3e..eb6934f769f 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -509,6 +509,21 @@ static int pdo_mysql_check_liveness(pdo_dbh_t *dbh) } /* }}} */ +/* {{{ pdo_mysql_request_shutdown */ +static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh) +{ + pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; + + PDO_DBG_ENTER("pdo_mysql_request_shutdown"); + PDO_DBG_INF_FMT("dbh=%p", dbh); +#ifdef PDO_USE_MYSQLND + if (H->server) { + mysqlnd_end_psession(H->server); + } +#endif +} +/* }}} */ + /* {{{ mysql_methods */ static const struct pdo_dbh_methods mysql_methods = { mysql_handle_closer, @@ -524,7 +539,7 @@ static const struct pdo_dbh_methods mysql_methods = { pdo_mysql_get_attribute, pdo_mysql_check_liveness, NULL, - NULL, + pdo_mysql_request_shutdown, NULL }; /* }}} */ @@ -589,6 +604,11 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) pdo_mysql_error(dbh); goto cleanup; } +#if defined(PDO_USE_MYSQLND) + if (dbh->is_persistent) { + mysqlnd_restart_psession(H->server); + } +#endif dbh->driver_data = H; diff --git a/ext/pdo_mysql/tests/bug77289.phpt b/ext/pdo_mysql/tests/bug77289.phpt new file mode 100644 index 00000000000..db675242607 --- /dev/null +++ b/ext/pdo_mysql/tests/bug77289.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #77289: PDO MySQL segfaults with persistent connection +--SKIPIF-- + +--FILE-- + true]); +$pdo->exec("DROP TABLE IF EXISTS bug77289"); +$pdo->exec("CREATE TEMPORARY TABLE bug77289 (x INT)"); +$pdo->exec("UPDATE bug77289 SET x = x"); + +?> +===DONE=== +--EXPECT-- +===DONE===