summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/pgsql/config.m42
-rw-r--r--ext/pgsql/pgsql.c22
-rw-r--r--ext/pgsql/php_pgsql.h1
3 files changed, 25 insertions, 0 deletions
diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4
index efccb17e94..5793362ebd 100644
--- a/ext/pgsql/config.m4
+++ b/ext/pgsql/config.m4
@@ -57,6 +57,8 @@ if test "$PHP_PGSQL" != "no"; then
AC_CHECK_LIB(pq, PQcmdTuples,AC_DEFINE(HAVE_PQCMDTUPLES,1,[Broken libpq under windows]))
AC_CHECK_LIB(pq, PQoidValue,AC_DEFINE(HAVE_PQOIDVALUE,1,[Older PostgreSQL]))
AC_CHECK_LIB(pq, PQclientEncoding,AC_DEFINE(HAVE_PQCLIENTENCODING,1,[PostgreSQL 7.0.x or later]))
+ AC_CHECK_LIB(pq, PQparameterStatus,AC_DEFINE(HAVE_PQPARAMETERSTATUS,1,[PostgreSQL 7.4 or later]))
+ AC_CHECK_LIB(pq, PQprotocolVersion,AC_DEFINE(HAVE_PQPROTOCOLVERSION,1,[PostgreSQL 7.4 or later]))
AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibye]))
LIBS=$old_LIBS
LDFLAGS=$old_LDFLAGS
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index da39607302..1fa16651a5 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_version, NULL)
PHP_FE(pg_ping, NULL)
/* query functions */
PHP_FE(pg_query, NULL)
@@ -782,6 +783,7 @@ PHP_FUNCTION(pg_close)
#define PHP_PG_PORT 4
#define PHP_PG_TTY 5
#define PHP_PG_HOST 6
+#define PHP_PG_VERSION 7
/* {{{ php_pgsql_get_link_info
*/
@@ -831,6 +833,18 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
case PHP_PG_HOST:
Z_STRVAL_P(return_value) = PQhost(pgsql);
break;
+ case PHP_PG_VERSION:
+ array_init(return_value);
+ add_assoc_string(return_value, "client", PG_VERSION, 1);
+#if HAVE_PQPROTOCOLVERSION
+ add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql));
+#if HAVE_PQPARAMETERSTATUS
+ if (PQprotocolVersion(pgsql) >= 3) {
+ add_assoc_string(return_value, "server", PQparameterStatus(pgsql, "server_version"), 1);
+ }
+#endif
+#endif
+ return;
default:
RETURN_FALSE;
}
@@ -893,6 +907,14 @@ PHP_FUNCTION(pg_host)
}
/* }}} */
+/* {{{ proto array pg_version([resource connection])
+ Returns an array with client, protocol and server version (when available) */
+PHP_FUNCTION(pg_version)
+{
+ php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_VERSION);
+}
+/* }}} */
+
/* {{{ proto bool pg_ping(resource connection)
Ping database. If connection is bad, try to reconnect. */
PHP_FUNCTION(pg_ping)
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index 1ce637ae31..b9bdb483e9 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -71,6 +71,7 @@ PHP_FUNCTION(pg_dbname);
PHP_FUNCTION(pg_port);
PHP_FUNCTION(pg_tty);
PHP_FUNCTION(pg_options);
+PHP_FUNCTION(pg_version);
PHP_FUNCTION(pg_ping);
/* query functions */
PHP_FUNCTION(pg_query);