Skip to content

Commit

Permalink
Add PDO::checkLiveness method
Browse files Browse the repository at this point in the history
Exposes the driver's underlying pdo_dbh_check_liveness_func to PHP
scripts that may want to check if a connection is still open.
  • Loading branch information
ericnorris committed Aug 4, 2020
1 parent bfdbb90 commit 75cec3d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
23 changes: 23 additions & 0 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,29 @@ PHP_METHOD(PDO, query)
}
/* }}} */

/* {{{ Performs a liveness check */
PHP_METHOD(PDO, checkLiveness)
{
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);

ZEND_PARSE_PARAMETERS_NONE();

PDO_CONSTRUCT_CHECK;

if (!dbh->methods->check_liveness) {
zend_throw_exception_ex(php_pdo_get_exception(), 0, "This driver doesn't support checkLiveness");
RETURN_THROWS();
}

if (dbh->methods->check_liveness(dbh) != FAILURE) {
RETURN_TRUE;
}

PDO_HANDLE_DBH_ERR();
RETURN_FALSE;
}
/* }}} */

/* {{{ 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 */
PHP_METHOD(PDO, quote)
{
Expand Down
3 changes: 3 additions & 0 deletions ext/pdo/pdo_dbh.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public function __construct(string $dsn, ?string $username = null, ?string $pass
/** @return bool */
public function beginTransaction() {}

/** @return bool */
public function checkLiveness() {}

/** @return bool */
public function commit() {}

Expand Down
6 changes: 5 additions & 1 deletion ext/pdo/pdo_dbh_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 36270d1418fc4ddd8f79018372b0ef00fb6f5889 */
* Stub hash: 379b21e9f0e26c7095c7366fa1eac71388ba0014 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0)
Expand All @@ -11,6 +11,8 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_beginTransaction, 0, 0, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_PDO_checkLiveness arginfo_class_PDO_beginTransaction

#define arginfo_class_PDO_commit arginfo_class_PDO_beginTransaction

#define arginfo_class_PDO_errorCode arginfo_class_PDO_beginTransaction
Expand Down Expand Up @@ -59,6 +61,7 @@ ZEND_END_ARG_INFO()

ZEND_METHOD(PDO, __construct);
ZEND_METHOD(PDO, beginTransaction);
ZEND_METHOD(PDO, checkLiveness);
ZEND_METHOD(PDO, commit);
ZEND_METHOD(PDO, errorCode);
ZEND_METHOD(PDO, errorInfo);
Expand All @@ -77,6 +80,7 @@ ZEND_METHOD(PDO, setAttribute);
static const zend_function_entry class_PDO_methods[] = {
ZEND_ME(PDO, __construct, arginfo_class_PDO___construct, ZEND_ACC_PUBLIC)
ZEND_ME(PDO, beginTransaction, arginfo_class_PDO_beginTransaction, ZEND_ACC_PUBLIC)
ZEND_ME(PDO, checkLiveness, arginfo_class_PDO_checkLiveness, ZEND_ACC_PUBLIC)
ZEND_ME(PDO, commit, arginfo_class_PDO_commit, ZEND_ACC_PUBLIC)
ZEND_ME(PDO, errorCode, arginfo_class_PDO_errorCode, ZEND_ACC_PUBLIC)
ZEND_ME(PDO, errorInfo, arginfo_class_PDO_errorInfo, ZEND_ACC_PUBLIC)
Expand Down

0 comments on commit 75cec3d

Please sign in to comment.