Skip to content

Commit f5f60e6

Browse files
committed
Added new function pg_parameter_status()
1 parent ab36d72 commit f5f60e6

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

ext/pgsql/pgsql.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ function_entry pgsql_functions[] = {
9090
PHP_FE(pg_options, NULL)
9191
PHP_FE(pg_version, NULL)
9292
PHP_FE(pg_ping, NULL)
93+
#if HAVE_PQPARAMETERSTATUS
94+
PHP_FE(pg_parameter_status, NULL)
95+
#endif
9396
/* query functions */
9497
PHP_FE(pg_query, NULL)
9598
PHP_FE(pg_send_query, NULL)
@@ -928,6 +931,41 @@ PHP_FUNCTION(pg_version)
928931
}
929932
/* }}} */
930933

934+
#if HAVE_PQPARAMETERSTATUS
935+
/* {{{ proto string|false pg_parameter_status([resource connection,] string param_name)
936+
Returns the value of a server parameter */
937+
PHP_FUNCTION(pg_parameter_status)
938+
{
939+
zval *pgsql_link;
940+
int id;
941+
PGconn *pgsql;
942+
char *param;
943+
int len;
944+
945+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pgsql_link, &param, &len) == SUCCESS) {
946+
id = -1;
947+
} else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &param, &len) == SUCCESS) {
948+
pgsql_link = NULL;
949+
id = PGG(default_link);
950+
} else {
951+
RETURN_FALSE;
952+
}
953+
if (pgsql_link == NULL && id == -1) {
954+
RETURN_FALSE;
955+
}
956+
957+
ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
958+
959+
param = (char*)PQparameterStatus(pgsql, param);
960+
if (param) {
961+
RETURN_STRING(param, 1);
962+
} else {
963+
RETURN_FALSE;
964+
}
965+
}
966+
/* }}} */
967+
#endif
968+
931969
/* {{{ proto bool pg_ping([resource connection])
932970
Ping database. If connection is bad, try to reconnect. */
933971
PHP_FUNCTION(pg_ping)

ext/pgsql/php_pgsql.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ PHP_FUNCTION(pg_tty);
7373
PHP_FUNCTION(pg_options);
7474
PHP_FUNCTION(pg_version);
7575
PHP_FUNCTION(pg_ping);
76+
#if HAVE_PQPARAMETERSTATUS
77+
PHP_FUNCTION(pg_parameter_status);
78+
#endif
7679
/* query functions */
7780
PHP_FUNCTION(pg_query);
7881
PHP_FUNCTION(pg_send_query);

0 commit comments

Comments
 (0)