summaryrefslogtreecommitdiff
path: root/ext/pgsql/pgsql.c
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2002-10-02 02:41:21 +0000
committerYasuo Ohgaki <yohgaki@php.net>2002-10-02 02:41:21 +0000
commit2728440fdcaf73f453cac01958e4b07dd5cd987c (patch)
treea42b77cc885dd1c2d93238b9d6845aa9c1007605 /ext/pgsql/pgsql.c
parentf8f11ac0a2566f100d525fc2830b31ce20ac8f0e (diff)
downloadphp-git-2728440fdcaf73f453cac01958e4b07dd5cd987c.tar.gz
Added pg_ping()
Diffstat (limited to 'ext/pgsql/pgsql.c')
-rw-r--r--ext/pgsql/pgsql.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 4b3e4a2d00..0e7cd398ef 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -88,6 +88,7 @@ function_entry pgsql_functions[] = {
PHP_FE(pg_port, NULL)
PHP_FE(pg_tty, NULL)
PHP_FE(pg_options, NULL)
+ PHP_FE(pg_ping, NULL)
/* query functions */
PHP_FE(pg_query, NULL)
PHP_FE(pg_send_query, NULL)
@@ -146,7 +147,7 @@ function_entry pgsql_functions[] = {
PHP_FE(pg_set_client_encoding, NULL)
#endif
/* misc function */
- PHP_FE(pg_meta_data, NULL)
+ PHP_FE(pg_meta_data, NULL)
PHP_FE(pg_convert, NULL)
PHP_FE(pg_insert, NULL)
PHP_FE(pg_update, NULL)
@@ -840,6 +841,37 @@ PHP_FUNCTION(pg_host)
}
/* }}} */
+/* {{{ proto bool pg_ping([resource connection])
+ Ping database. If connection is bad, try to reconnect. */
+PHP_FUNCTION(pg_ping)
+{
+ zval *pgsql_link = NULL;
+ int id = -1;
+ PGconn *pgsql;
+
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r",
+ &pgsql_link) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+
+ /* ping connection */
+ PQexec(pgsql, "SELECT 1;");
+
+ /* check status. */
+ if (PQstatus(pgsql) == CONNECTION_OK)
+ RETURN_TRUE;
+
+ /* reset connection if it's broken */
+ PQreset(pgsql);
+ if (PQstatus(pgsql) == CONNECTION_OK) {
+ RETURN_TRUE;
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
/* {{{ proto resource pg_query([resource connection,] string query)
Execute a query */
PHP_FUNCTION(pg_query)