Skip to content

Commit 75cec3d

Browse files
committed
Add PDO::checkLiveness method
Exposes the driver's underlying pdo_dbh_check_liveness_func to PHP scripts that may want to check if a connection is still open.
1 parent bfdbb90 commit 75cec3d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,29 @@ PHP_METHOD(PDO, query)
10961096
}
10971097
/* }}} */
10981098

1099+
/* {{{ Performs a liveness check */
1100+
PHP_METHOD(PDO, checkLiveness)
1101+
{
1102+
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
1103+
1104+
ZEND_PARSE_PARAMETERS_NONE();
1105+
1106+
PDO_CONSTRUCT_CHECK;
1107+
1108+
if (!dbh->methods->check_liveness) {
1109+
zend_throw_exception_ex(php_pdo_get_exception(), 0, "This driver doesn't support checkLiveness");
1110+
RETURN_THROWS();
1111+
}
1112+
1113+
if (dbh->methods->check_liveness(dbh) != FAILURE) {
1114+
RETURN_TRUE;
1115+
}
1116+
1117+
PDO_HANDLE_DBH_ERR();
1118+
RETURN_FALSE;
1119+
}
1120+
/* }}} */
1121+
10991122
/* {{{ quotes string for use in a query. The optional paramtype acts as a hint for drivers that have alternate quoting styles. The default value is PDO_PARAM_STR */
11001123
PHP_METHOD(PDO, quote)
11011124
{

ext/pdo/pdo_dbh.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public function __construct(string $dsn, ?string $username = null, ?string $pass
99
/** @return bool */
1010
public function beginTransaction() {}
1111

12+
/** @return bool */
13+
public function checkLiveness() {}
14+
1215
/** @return bool */
1316
public function commit() {}
1417

ext/pdo/pdo_dbh_arginfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 36270d1418fc4ddd8f79018372b0ef00fb6f5889 */
2+
* Stub hash: 379b21e9f0e26c7095c7366fa1eac71388ba0014 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0)
@@ -11,6 +11,8 @@ ZEND_END_ARG_INFO()
1111
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_beginTransaction, 0, 0, 0)
1212
ZEND_END_ARG_INFO()
1313

14+
#define arginfo_class_PDO_checkLiveness arginfo_class_PDO_beginTransaction
15+
1416
#define arginfo_class_PDO_commit arginfo_class_PDO_beginTransaction
1517

1618
#define arginfo_class_PDO_errorCode arginfo_class_PDO_beginTransaction
@@ -59,6 +61,7 @@ ZEND_END_ARG_INFO()
5961

6062
ZEND_METHOD(PDO, __construct);
6163
ZEND_METHOD(PDO, beginTransaction);
64+
ZEND_METHOD(PDO, checkLiveness);
6265
ZEND_METHOD(PDO, commit);
6366
ZEND_METHOD(PDO, errorCode);
6467
ZEND_METHOD(PDO, errorInfo);
@@ -77,6 +80,7 @@ ZEND_METHOD(PDO, setAttribute);
7780
static const zend_function_entry class_PDO_methods[] = {
7881
ZEND_ME(PDO, __construct, arginfo_class_PDO___construct, ZEND_ACC_PUBLIC)
7982
ZEND_ME(PDO, beginTransaction, arginfo_class_PDO_beginTransaction, ZEND_ACC_PUBLIC)
83+
ZEND_ME(PDO, checkLiveness, arginfo_class_PDO_checkLiveness, ZEND_ACC_PUBLIC)
8084
ZEND_ME(PDO, commit, arginfo_class_PDO_commit, ZEND_ACC_PUBLIC)
8185
ZEND_ME(PDO, errorCode, arginfo_class_PDO_errorCode, ZEND_ACC_PUBLIC)
8286
ZEND_ME(PDO, errorInfo, arginfo_class_PDO_errorInfo, ZEND_ACC_PUBLIC)

0 commit comments

Comments
 (0)