php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #62065
Patch PHP72_Add_PDO_Close.patch revision 2018-05-31 09:34 UTC by cato at timeanddate dot com

Patch PHP72_Add_PDO_Close.patch for PDO related Bug #62065

Patch version 2018-05-31 09:34 UTC

Return to Bug #62065 | Download this patch
Patch Revisions:

Developer: cato@timeanddate.com

diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 4a372a9c18..0982555b7e 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -973,6 +973,31 @@ static PHP_METHOD(PDO, lastInsertId)
 }
 /* }}} */
 
+/* {{{ proto bool PDO::close()
+   Close the database connection */
+static PHP_METHOD(PDO, close)
+{
+	pdo_dbh_t *dbh = Z_PDO_DBH_P(getThis());
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PDO_CONSTRUCT_CHECK;
+
+	if (dbh->in_txn && dbh->methods && dbh->methods->rollback) {
+		dbh->methods->rollback(dbh);
+		dbh->in_txn = 0;
+	}
+
+	if (dbh->methods && dbh->methods->closer(dbh) == 0) {
+		RETURN_TRUE;
+	}
+
+	RETURN_FALSE;
+}
+/* }}} */
+
 /* {{{ proto string PDO::errorCode()
    Fetch the error code associated with the last operation on the database handle */
 static PHP_METHOD(PDO, errorCode)
@@ -1255,6 +1280,7 @@ const zend_function_entry pdo_dbh_functions[] = /* {{{ */ {
 	PHP_ME(PDO, __wakeup,               arginfo_pdo__void,         ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
 	PHP_ME(PDO, __sleep,                arginfo_pdo__void,         ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
 	PHP_ME(PDO, getAvailableDrivers,    arginfo_pdo__void,         ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+	PHP_ME(PDO, close,    arginfo_pdo__void,         ZEND_ACC_PUBLIC)
 	PHP_FE_END
 };
 /* }}} */
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC