summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql/mysql_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo_mysql/mysql_driver.c')
-rw-r--r--ext/pdo_mysql/mysql_driver.c88
1 files changed, 36 insertions, 52 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c
index c0708ceb12..b7b6770327 100644
--- a/ext/pdo_mysql/mysql_driver.c
+++ b/ext/pdo_mysql/mysql_driver.c
@@ -18,8 +18,6 @@
+----------------------------------------------------------------------+
*/
-/* $Id$ */
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -349,11 +347,7 @@ static int mysql_handle_commit(pdo_dbh_t *dbh)
{
PDO_DBG_ENTER("mysql_handle_commit");
PDO_DBG_INF_FMT("dbh=%p", dbh);
-#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
PDO_DBG_RETURN(0 == mysql_commit(((pdo_mysql_db_handle *)dbh->driver_data)->server));
-#else
- PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("COMMIT")));
-#endif
}
/* }}} */
@@ -362,11 +356,7 @@ static int mysql_handle_rollback(pdo_dbh_t *dbh)
{
PDO_DBG_ENTER("mysql_handle_rollback");
PDO_DBG_INF_FMT("dbh=%p", dbh);
-#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
PDO_DBG_RETURN(0 <= mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server));
-#else
- PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK")));
-#endif
}
/* }}} */
@@ -376,15 +366,7 @@ static inline int mysql_handle_autocommit(pdo_dbh_t *dbh)
PDO_DBG_ENTER("mysql_handle_autocommit");
PDO_DBG_INF_FMT("dbh=%p", dbh);
PDO_DBG_INF_FMT("dbh->autocommit=%d", dbh->auto_commit);
-#if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND)
PDO_DBG_RETURN(0 <= mysql_autocommit(((pdo_mysql_db_handle *)dbh->driver_data)->server, dbh->auto_commit));
-#else
- if (dbh->auto_commit) {
- PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=1")));
- } else {
- PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=0")));
- }
-#endif
}
/* }}} */
@@ -522,37 +504,34 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
static int pdo_mysql_check_liveness(pdo_dbh_t *dbh)
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
-#if MYSQL_VERSION_ID <= 32230
- void (*handler) (int);
- unsigned int my_errno;
-#endif
PDO_DBG_ENTER("pdo_mysql_check_liveness");
PDO_DBG_INF_FMT("dbh=%p", dbh);
-#if MYSQL_VERSION_ID > 32230
if (mysql_ping(H->server)) {
PDO_DBG_RETURN(FAILURE);
}
-#else /* no mysql_ping() */
- handler = signal(SIGPIPE, SIG_IGN);
- mysql_stat(H->server);
- switch (mysql_errno(H->server)) {
- case CR_SERVER_GONE_ERROR:
- case CR_SERVER_LOST:
- signal(SIGPIPE, handler);
- PDO_DBG_RETURN(FAILURE);
- default:
- break;
- }
- signal(SIGPIPE, handler);
-#endif /* end mysql_ping() */
PDO_DBG_RETURN(SUCCESS);
}
/* }}} */
+/* {{{ 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 struct pdo_dbh_methods mysql_methods = {
+static const struct pdo_dbh_methods mysql_methods = {
mysql_handle_closer,
mysql_handle_preparer,
mysql_handle_doer,
@@ -566,7 +545,7 @@ static struct pdo_dbh_methods mysql_methods = {
pdo_mysql_get_attribute,
pdo_mysql_check_liveness,
NULL,
- NULL,
+ pdo_mysql_request_shutdown,
NULL
};
/* }}} */
@@ -631,6 +610,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;
@@ -702,31 +686,31 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
init_cmd = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_INIT_COMMAND, NULL);
if (init_cmd) {
if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const char *)ZSTR_VAL(init_cmd))) {
- zend_string_release(init_cmd);
+ zend_string_release_ex(init_cmd, 0);
pdo_mysql_error(dbh);
goto cleanup;
}
- zend_string_release(init_cmd);
+ zend_string_release_ex(init_cmd, 0);
}
#ifndef PDO_USE_MYSQLND
default_file = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_FILE, NULL);
if (default_file) {
if (mysql_options(H->server, MYSQL_READ_DEFAULT_FILE, (const char *)ZSTR_VAL(default_file))) {
- zend_string_release(default_file);
+ zend_string_release_ex(default_file, 0);
pdo_mysql_error(dbh);
goto cleanup;
}
- zend_string_release(default_file);
+ zend_string_release_ex(default_file, 0);
}
default_group = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_GROUP, NULL);
if (default_group) {
if (mysql_options(H->server, MYSQL_READ_DEFAULT_GROUP, (const char *)ZSTR_VAL(default_group))) {
- zend_string_release(default_group);
+ zend_string_release_ex(default_group, 0);
pdo_mysql_error(dbh);
goto cleanup;
}
- zend_string_release(default_group);
+ zend_string_release_ex(default_group, 0);
}
#endif
compress = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_COMPRESS, 0);
@@ -751,19 +735,19 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
ssl_capath? ZSTR_VAL(ssl_capath) : NULL,
ssl_cipher? ZSTR_VAL(ssl_cipher) : NULL);
if (ssl_key) {
- zend_string_release(ssl_key);
+ zend_string_release_ex(ssl_key, 0);
}
if (ssl_cert) {
- zend_string_release(ssl_cert);
+ zend_string_release_ex(ssl_cert, 0);
}
if (ssl_ca) {
- zend_string_release(ssl_ca);
+ zend_string_release_ex(ssl_ca, 0);
}
if (ssl_capath) {
- zend_string_release(ssl_capath);
+ zend_string_release_ex(ssl_capath, 0);
}
if (ssl_cipher) {
- zend_string_release(ssl_cipher);
+ zend_string_release_ex(ssl_cipher, 0);
}
}
@@ -773,10 +757,10 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
if (public_key) {
if (mysql_options(H->server, MYSQL_SERVER_PUBLIC_KEY, ZSTR_VAL(public_key))) {
pdo_mysql_error(dbh);
- zend_string_release(public_key);
+ zend_string_release_ex(public_key, 0);
goto cleanup;
}
- zend_string_release(public_key);
+ zend_string_release_ex(public_key, 0);
}
}
#endif
@@ -868,7 +852,7 @@ cleanup:
}
/* }}} */
-pdo_driver_t pdo_mysql_driver = {
+const pdo_driver_t pdo_mysql_driver = {
PDO_DRIVER_HEADER(mysql),
pdo_mysql_handle_factory
};