mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Added pg_ping()
This commit is contained in:
parent
f8f11ac0a2
commit
2728440fdc
3 changed files with 35 additions and 2 deletions
2
NEWS
2
NEWS
|
@ -7,7 +7,7 @@ PHP 4 NEWS
|
||||||
- Fixed bug #17825 (ob_start() chunk size option didn't work well). (Yasuo)
|
- Fixed bug #17825 (ob_start() chunk size option didn't work well). (Yasuo)
|
||||||
- Fixed output buffering implicit flush. (Yasuo)
|
- Fixed output buffering implicit flush. (Yasuo)
|
||||||
- Added getopt() for parsing command line options and arguments. (Jon)
|
- Added getopt() for parsing command line options and arguments. (Jon)
|
||||||
- Added pg_fetch_assoc(), pg_fetch_all(), pg_meta_data(), pg_convert(),
|
- Added pg_fetch_assoc(), pg_fetch_all(), pg_ping(), pg_meta_data(), pg_convert(),
|
||||||
pg_insert(), pg_select(), pg_update() and pg_delete(). (Yasuo)
|
pg_insert(), pg_select(), pg_update() and pg_delete(). (Yasuo)
|
||||||
- Fixed bug #17281 (Sanity checks for encoding sessions). (Ilia)
|
- Fixed bug #17281 (Sanity checks for encoding sessions). (Ilia)
|
||||||
- Fixed bug #16995 and #19392 (Prevent crash if $HTTP_SESSION_VARS != ARRAY).
|
- Fixed bug #16995 and #19392 (Prevent crash if $HTTP_SESSION_VARS != ARRAY).
|
||||||
|
|
|
@ -88,6 +88,7 @@ function_entry pgsql_functions[] = {
|
||||||
PHP_FE(pg_port, NULL)
|
PHP_FE(pg_port, NULL)
|
||||||
PHP_FE(pg_tty, NULL)
|
PHP_FE(pg_tty, NULL)
|
||||||
PHP_FE(pg_options, NULL)
|
PHP_FE(pg_options, NULL)
|
||||||
|
PHP_FE(pg_ping, NULL)
|
||||||
/* query functions */
|
/* query functions */
|
||||||
PHP_FE(pg_query, NULL)
|
PHP_FE(pg_query, NULL)
|
||||||
PHP_FE(pg_send_query, NULL)
|
PHP_FE(pg_send_query, NULL)
|
||||||
|
@ -146,7 +147,7 @@ function_entry pgsql_functions[] = {
|
||||||
PHP_FE(pg_set_client_encoding, NULL)
|
PHP_FE(pg_set_client_encoding, NULL)
|
||||||
#endif
|
#endif
|
||||||
/* misc function */
|
/* misc function */
|
||||||
PHP_FE(pg_meta_data, NULL)
|
PHP_FE(pg_meta_data, NULL)
|
||||||
PHP_FE(pg_convert, NULL)
|
PHP_FE(pg_convert, NULL)
|
||||||
PHP_FE(pg_insert, NULL)
|
PHP_FE(pg_insert, NULL)
|
||||||
PHP_FE(pg_update, 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)
|
/* {{{ proto resource pg_query([resource connection,] string query)
|
||||||
Execute a query */
|
Execute a query */
|
||||||
PHP_FUNCTION(pg_query)
|
PHP_FUNCTION(pg_query)
|
||||||
|
|
|
@ -71,6 +71,7 @@ PHP_FUNCTION(pg_dbname);
|
||||||
PHP_FUNCTION(pg_port);
|
PHP_FUNCTION(pg_port);
|
||||||
PHP_FUNCTION(pg_tty);
|
PHP_FUNCTION(pg_tty);
|
||||||
PHP_FUNCTION(pg_options);
|
PHP_FUNCTION(pg_options);
|
||||||
|
PHP_FUNCTION(pg_ping);
|
||||||
/* query functions */
|
/* query functions */
|
||||||
PHP_FUNCTION(pg_query);
|
PHP_FUNCTION(pg_query);
|
||||||
PHP_FUNCTION(pg_send_query);
|
PHP_FUNCTION(pg_send_query);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue