本文整理汇总了PHP中pg_ping函数的典型用法代码示例。如果您正苦于以下问题:PHP pg_ping函数的具体用法?PHP pg_ping怎么用?PHP pg_ping使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pg_ping函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ping
function ping()
{
if (!$this->conn) {
return $this->connect();
}
return pg_ping($this->conn);
}
示例2: is_connected
public function is_connected()
{
return $this->connection_handle && pg_ping($this->connection_handle);
}
示例3: reconnect
/**
* Reconnect.
*
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
* @return void
*/
public function reconnect()
{
if (pg_ping($this->conn_id) === false) {
$this->conn_id = false;
}
}
示例4: _check_connect
/**
* 检查连接是否可用
*
* 防止因长时间不链接而导致连接丢失的问题 server has gone away
*
* @throws Exception
*/
protected function _check_connect()
{
# 5秒检测1次
static $error_num = 0;
try {
$connection_id = $this->connection_id();
$connection = Database_Driver_Postgre::$_connection_instance[$connection_id];
if ($connection) {
$ping_status = pg_ping($connection);
} else {
$ping_status = false;
}
} catch (Exception $e) {
$error_num++;
$ping_status = false;
}
if (!$ping_status) {
if ($error_num < 5) {
$this->close_connect();
# 等待3毫秒
usleep(3000);
# 再次尝试连接
$this->connect();
$error_num = 0;
} else {
throw new Exception('connect postgre server error');
}
}
}
示例5: ping
/**
* Checks, if the connection to the server is still alive
*
* @return bool
*/
public function ping()
{
// Checks, if the connection to the server is still alive
if (!$this->objServer) {
throw new Exception('No SQL resource available. Could not execute ping.');
}
return \pg_ping($this->objServer);
}
示例6: tryOpenDataBase
/**
* This function tries to open to the DB
*
* @param string $pDbDriver
* @param array $arrayServerData
*
* @return void
*/
public function tryOpenDataBase($pDbDriver, array $arrayServerData = array())
{
if ($this->errno != 0) {
return 0;
}
set_time_limit(0);
$stat = new Stat();
$flagTns = isset($arrayServerData["connectionType"]) && $arrayServerData["connectionType"] == "TNS" ? 1 : 0;
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
switch ($pDbDriver) {
case 'mysql':
$link = @mysql_connect($this->ip . ($this->db_port != '' && $this->db_port != 0 ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd);
$db = @mysql_select_db($this->db_sourcename);
if ($link) {
if ($db) {
$result = @mysql_query("show tables;");
if ($result) {
$stat->status = 'SUCCESS';
$this->errstr = "";
$this->errno = 0;
@mysql_free_result($result);
} else {
$this->error = "the user {$this->db_user} doesn't have privileges to run queries!";
$this->errstr = "NET::MYSQL->Test query failed";
$this->errno = 10100;
}
} else {
$this->error = "The {$this->db_sourcename} data base does'n exist!";
$this->errstr = "NET::MYSQL->Select data base failed";
$this->errno = 10011;
}
} else {
$this->error = "MySql connection refused!";
$this->errstr = "NET::MYSQL->The connection was refused";
$this->errno = 10001;
}
break;
case 'pgsql':
$this->db_port = $this->db_port == "" || $this->db_port == 0 ? "5432" : $this->db_port;
$link = @pg_connect("host='{$this->ip}' port='{$this->db_port}' user='{$this->db_user}' password='{$this->db_passwd}' dbname='{$this->db_sourcename}'");
if ($link) {
if (@pg_ping($link)) {
$stat->status = 'SUCCESS';
$this->errstr = "";
$this->errno = 0;
} else {
$this->error = "PostgreSql Connection to {$this->ip} is unreachable!";
$this->errstr = "NET::POSTGRES->Lost Connection";
$this->errno = 20010;
}
} else {
$this->error = "PostgrSql connection refused";
$this->errstr = "NET::POSTGRES->The connection was refused";
$this->errno = 20001;
}
break;
case 'mssql':
// $str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port;
// $link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
if ($this->db_instance != "") {
$str_port = "";
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$str_port = $this->db_port == "" || $this->db_port == 0 || $this->db_port == 1433 ? "" : ":" . $this->db_port;
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
}
if ($link) {
$db = @mssql_select_db($this->db_sourcename, $link);
if ($db) {
$stat->status = 'SUCCESS';
$this->errstr = "";
$this->errno = 0;
} else {
$this->error = "The {$this->db_sourcename} data base does'n exist!";
$this->errstr = "NET::MSSQL->Select data base failed";
$this->errno = 30010;
}
} else {
$this->error = "MS-SQL Server connection refused!";
$this->errstr = "NET::MSSQL->The connection was refused";
$this->errno = 30001;
}
break;
case 'oracle':
if ($flagTns == 0) {
$this->db_port = $this->db_port == "" || $this->db_port == 0 ? "1521" : $this->db_port;
$cnn = @oci_connect($this->db_user, $this->db_passwd, "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (HOST={$this->ip}) (PORT={$this->db_port}) )) (CONNECT_DATA=(SERVICE_NAME={$this->db_sourcename})))");
} else {
$cnn = @oci_connect($this->db_user, $this->db_passwd, $arrayServerData["tns"]);
}
if ($cnn) {
$stid = @oci_parse($cnn, 'select AUTHENTICATION_TYPE from v$session_connect_info');
//.........这里部分代码省略.........
示例7: ping
public function ping()
{
return pg_ping($this->connection);
}
示例8: check_connection
/**
* Check the connection to PgSQL if Active and Not Busy
* If not connected will connect
* PRIVATE
*
* @param RESOURCE $y_connection :: The Connection to PgSQL Server
* @param STRING $y_description :: The Description of Where it is Checked (for having a clue where it fails)
* @return Connection Resource
*
*/
private static function check_connection($y_connection, $y_description)
{
//--
global $configs;
//--
if ($y_connection === 'DEFAULT') {
// just for the default connection !!!
//--
if (!defined('SMART_FRAMEWORK_DB_LINK_PostgreSQL')) {
// PostgreSQL default connection is exported as constant to avoid re-connection which can break transactions
//--
if (!is_array($configs['pgsql'])) {
self::error('', 'CHECK-DEFAULT-PGSQL-CONFIGS', 'The Default PostgreSQL Configs not detected !', 'The configs[pgsql] is not an array !', $y_description);
return null;
}
//end if
if ((string) $configs['pgsql']['server-host'] == '' or (string) $configs['pgsql']['server-port'] == '' or (string) $configs['pgsql']['dbname'] == '' or (string) $configs['pgsql']['username'] == '') {
self::error('', 'CHECK-DEFAULT-PGSQL-CONFIGS', 'The Default PostgreSQL Configs are not complete !', 'Some of the configs[pgsql] parameters are missing !', $y_description);
return null;
}
//end if
//-- {{{SYNC-CONNECTIONS-IDS}}}
$the_conn_key = (string) $configs['pgsql']['server-host'] . ':' . $configs['pgsql']['server-port'] . '@' . $configs['pgsql']['dbname'] . '#' . $configs['pgsql']['username'] . '>' . trim(strtoupper(str_replace(' ', '', (string) $configs['pgsql']['transact']))) . '.';
if (array_key_exists((string) $the_conn_key, (array) SmartFrameworkRegistry::$Connections['pgsql'])) {
// if the connection was made before using the SmartPgsqlExtDb
//--
$y_connection = SmartFrameworkRegistry::$Connections['pgsql'][(string) $the_conn_key];
//--
define('SMART_FRAMEWORK_DB_LINK_PostgreSQL', $y_connection);
//--
if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'open-close', 'data' => 'Re-Using Connection to PgSQL Server as DEFAULT: ' . $the_conn_key, 'connection' => (string) $y_connection]);
}
//end if
//--
} else {
//--
$y_connection = self::server_connect((string) $configs['pgsql']['server-host'], (int) $configs['pgsql']['server-port'], (string) $configs['pgsql']['dbname'], (string) $configs['pgsql']['username'], (string) $configs['pgsql']['password'], (int) $configs['pgsql']['timeout'], (string) $configs['pgsql']['transact'], (double) $configs['pgsql']['slowtime'], (string) $configs['pgsql']['type']);
//--
define('SMART_FRAMEWORK_DB_LINK_PostgreSQL', $y_connection);
//--
if (is_resource($y_connection)) {
//--
define('SMART_FRAMEWORK_DB_VERSION_PostgreSQL', self::check_server_version($y_connection, true));
// re-validate
//--
}
//end if
//--
}
//end if else
//--
} else {
//-- re-use the default connection
$y_connection = SMART_FRAMEWORK_DB_LINK_PostgreSQL;
//--
}
//end if
//--
}
//end if
//--
if (!is_resource($y_connection)) {
// if no connection
//--
self::error($y_connection, 'CHECK-CONNECTION', 'Connection is BROKEN !', 'Connection-ID: ' . $y_connection, $y_description);
return null;
//--
}
//end if
//--
if (@pg_connection_status($y_connection) != PGSQL_CONNECTION_OK) {
//--
$re_connect = @pg_ping($y_connection);
//--
if (!$re_connect) {
self::error($y_connection, 'CHECK-CONNECTION', 'Connection LOST !', 'Connection-ID: ' . $y_connection, $y_description);
return null;
}
//end if
//--
}
//end if else
//--
return $y_connection;
//--
}
示例9: ping
/**
* Vérifie l'état de la connexion courante et effectue si besoin une reconnexion
*
* @access public
* @return boolean
*/
function ping()
{
return pg_ping($this->link);
}
示例10: ping
/**
* transmit a ping against the database
*
* @return bool true | false
*/
public function ping()
{
return pg_ping($this->dbh) ? true : false;
}
示例11: hasDbConnection
/**
* @return bool
*/
protected function hasDbConnection()
{
if ($this->pg_conn) {
return pg_ping($this->pg_conn);
} else {
return pg_ping();
}
}
示例12: getProtocolInfo
public function getProtocolInfo()
{
return pg_ping($this->link);
}
示例13: pg_connect
<?php
// optional functions
include 'config.inc';
$db = pg_connect($conn_str);
var_dump(pg_ping($db));
示例14: connected
/**
* Determines if the connection to the server is active.
*
* @return boolean
*
* @since 12.1
*/
public function connected()
{
$this->connect();
if (is_resource($this->connection)) {
return pg_ping($this->connection);
}
return false;
}
示例15: isValid
function isValid()
{
return @pg_ping($this->getConnectionId());
}