当前位置: 首页>>代码示例>>PHP>>正文


PHP pg_connection_status函数代码示例

本文整理汇总了PHP中pg_connection_status函数的典型用法代码示例。如果您正苦于以下问题:PHP pg_connection_status函数的具体用法?PHP pg_connection_status怎么用?PHP pg_connection_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pg_connection_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _connect

 protected function _connect()
 {
     $connstr = '';
     foreach ($this->_config as $param => $value) {
         if ($value) {
             switch ($param) {
                 case 'host':
                     $connstr .= "host={$value} ";
                     break;
                 case 'database':
                     $connstr .= "dbname={$value} ";
                     break;
                 case 'port':
                     $connstr .= "port={$value} ";
                     break;
                 case 'username':
                     $connstr .= "user={$value} ";
                     break;
                 case 'password':
                     $connstr .= "password={$value} ";
                     break;
             }
         }
     }
     if (isset($this->_config['persistent'])) {
         $this->_connection = pg_pconnect($connstr);
     } else {
         $this->_connection = pg_connect($connstr);
     }
     if (pg_connection_status($this->_connection) !== PGSQL_CONNECTION_OK) {
         $this->_errorHandler(1, "Cconnection failed. ");
     }
 }
开发者ID:TheProjecter,项目名称:skeleton,代码行数:33,代码来源:Postgres.php

示例2: connect

 public function connect()
 {
     if ($this->bConnected) {
         return $this->rConnection;
     }
     $iLevel = error_reporting();
     // to suppress E_WARNING that can happen
     error_reporting(0);
     if ($this->iPersistence == 0) {
         // plain connect
         $this->rConnection = pg_connect($this->sConnString, PGSQL_CONNECT_FORCE_NEW);
     } else {
         if ($this->iPersistence == 1) {
             // persistent connect
             $this->rConnection = pg_pconnect($this->sConnString);
         } else {
             if ($this->iPersistence == PGSQL_CONNECT_FORCE_NEW) {
                 // persistent connect forced new
                 $this->rConnection = pg_connect($this->sConnString, PGSQL_CONNECT_FORCE_NEW);
             }
         }
     }
     // lets restore previous level
     error_reporting($iLevel);
     $iConnStatus = pg_connection_status($this->rConnection);
     if ($iConnStatus !== PGSQL_CONNECTION_OK) {
         if (is_resource($this->rConnection)) {
             pg_close($this->rConnection);
         }
         throw new \Exception('Unable to connect.');
     }
     $this->bConnected = true;
     return $this->rConnection;
 }
开发者ID:denismilovanov,项目名称:libpostgres,代码行数:34,代码来源:LibPostgresDriver.php

示例3: castLink

 public static function castLink($link, array $a, Stub $stub, $isNested)
 {
     $a['status'] = pg_connection_status($link);
     $a['status'] = new ConstStub(PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
     $a['busy'] = pg_connection_busy($link);
     $a['transaction'] = pg_transaction_status($link);
     if (isset(self::$transactionStatus[$a['transaction']])) {
         $a['transaction'] = new ConstStub(self::$transactionStatus[$a['transaction']], $a['transaction']);
     }
     $a['pid'] = pg_get_pid($link);
     $a['last error'] = pg_last_error($link);
     $a['last notice'] = pg_last_notice($link);
     $a['host'] = pg_host($link);
     $a['port'] = pg_port($link);
     $a['dbname'] = pg_dbname($link);
     $a['options'] = pg_options($link);
     $a['version'] = pg_version($link);
     foreach (self::$paramCodes as $v) {
         if (false !== ($s = pg_parameter_status($link, $v))) {
             $a['param'][$v] = $s;
         }
     }
     $a['param']['client_encoding'] = pg_client_encoding($link);
     $a['param'] = new EnumStub($a['param']);
     return $a;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:26,代码来源:PgSqlCaster.php

示例4: connect

 /**
  * 连接数据库方法
  * @access public
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         $conn = $pconnect ? 'pg_pconnect' : 'pg_connect';
         $this->linkID[$linkNum] = $conn('host=' . $config['hostname'] . ' port=' . $config['hostport'] . ' dbname=' . $config['database'] . ' user=' . $config['username'] . '  password=' . $config['password']);
         if (0 !== pg_connection_status($this->linkID[$linkNum])) {
             E($this->error(false));
         }
         //设置编码
         pg_set_client_encoding($this->linkID[$linkNum], $config['charset']);
         //$pgInfo = pg_version($this->linkID[$linkNum]);
         //$dbVersion = $pgInfo['server'];
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
开发者ID:2flying2,项目名称:IDF-CTF-PLAT,代码行数:29,代码来源:Pgsql.class.php

示例5: getAttribute

 public function getAttribute($attribute, &$source = null, $func = 'PDO::getAttribute', &$last_error = null)
 {
     switch ($attribute) {
         case PDO::ATTR_AUTOCOMMIT:
             return $this->autocommit;
             break;
         case PDO::ATTR_CLIENT_VERSION:
             $ver = pg_version($this->link);
             return $ver['client'];
             break;
         case PDO::ATTR_CONNECTION_STATUS:
             if (pg_connection_status($this->link) === PGSQL_CONNECTION_OK) {
                 return 'Connection OK; waiting to send.';
             } else {
                 return 'Connection BAD';
             }
             break;
         case PDO::ATTR_SERVER_INFO:
             return sprintf('PID: %d; Client Encoding: %s; Is Superuser: %s; Session Authorization: %s; Date Style: %s', pg_get_pid($this->link), pg_client_encoding($this->link), pg_parameter_status($this->link, 'is_superuser'), pg_parameter_status($this->link, 'session_authorization'), pg_parameter_status($this->link, 'DateStyle'));
             break;
         case PDO::ATTR_SERVER_VERSION:
             return pg_parameter_status($this->link, 'server_version');
             break;
         default:
             return parent::getAttribute($attribute, $source, $func, $last_error);
             break;
     }
 }
开发者ID:PHPcomaptibility,项目名称:PHPPDO,代码行数:28,代码来源:pgsql.php

示例6: __construct

 function __construct($db_host, $db_user, $db_password, $db_name, $backend = "mysql")
 {
     define("DeveloperMailAddress", "claudio.giordano@autistici.org");
     define("RegDataMySql", "([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])");
     define("RegDataIt", "([0-3][0-9]/[0-1][0-9]/[1-2][0-9][0-9][0-9])");
     define("RegTime", "([0-2][0-9]:[0-6][0-9]:[0-6][0-9])");
     define("RegDataTime", "([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9])");
     $this->ReportHeader = "";
     $this->ReportFields = "";
     $this->BackEnd = $backend;
     $this->ResultStatus = "";
     $this->LastID = "";
     $this->SaveErrors = "";
     switch ($backend) {
         case "mysql":
             if (!($this->db = mysqli_connect($db_host, $db_user, $db_password))) {
                 $this->StampaErr("mysql_connect", "Errore durante la connessione al database," . " verificare i parametri.");
                 exit;
             }
             if (!mysqli_select_db($this->db, $db_name)) {
                 $this->StampaErr("mysql_select_db", "Errore durante la selezione del database," . " verificare i parametri.");
                 exit;
             }
             break;
         case "postgresql":
             if (!($this->db = pg_connect("host={$db_host} port=5432 dbname={$db_name} user={$db_user} password={$db_password}"))) {
                 echo "[Debug]: pg_connection_status: " . pg_connection_status($this->db) . " <br />";
                 $this->StampaErr("pg_connect", "Errore durante la connessione\n                            o selezione del database, verificare i parametri.");
                 exit;
             }
             break;
     }
     return $this->db;
 }
开发者ID:clagiordano,项目名称:weblibs,代码行数:34,代码来源:DatabaseLegacy.php

示例7: connect

 /**
  * Connect to database
  *
  * @param array $options
  * @return array
  */
 public function connect($options)
 {
     $result = ['version' => null, 'status' => 0, 'error' => [], 'errno' => 0, 'success' => false];
     // we could pass an array or connection string right a way
     if (is_array($options)) {
         $str = 'host=' . $options['host'] . ' port=' . $options['port'] . ' dbname=' . $options['dbname'] . ' user=' . $options['username'] . ' password=' . $options['password'];
     } else {
         $str = $options;
     }
     $connection = pg_connect($str);
     if ($connection !== false) {
         $this->db_resource = $connection;
         $this->connect_options = $options;
         $this->commit_status = 0;
         pg_set_error_verbosity($connection, PGSQL_ERRORS_VERBOSE);
         pg_set_client_encoding($connection, 'UNICODE');
         $result['version'] = pg_version($connection);
         $result['status'] = pg_connection_status($connection) === PGSQL_CONNECTION_OK ? 1 : 0;
         $result['success'] = true;
     } else {
         $result['error'][] = 'db::connect() : Could not connect to database server!';
         $result['errno'] = 1;
     }
     return $result;
 }
开发者ID:volodymyr-volynets,项目名称:backend,代码行数:31,代码来源:base.php

示例8: connect

 public function connect($parameters, $selectDB = false)
 {
     $this->lastParameters = $parameters;
     // Note: Postgres always behaves as though $selectDB = true, ignoring
     // any value actually passed in. The controller passes in true for other
     // connectors such as PDOConnector.
     // Escape parameters
     $arguments = array($this->escapeParameter($parameters, 'server', 'host', 'localhost'), $this->escapeParameter($parameters, 'port', 'port', 5432), $this->escapeParameter($parameters, 'database', 'dbname', 'postgres'), $this->escapeParameter($parameters, 'username', 'user'), $this->escapeParameter($parameters, 'password', 'password'));
     // Close the old connection
     if ($this->dbConn) {
         pg_close($this->dbConn);
     }
     // Connect
     $this->dbConn = @pg_connect(implode(' ', $arguments));
     if ($this->dbConn === false) {
         // Extract error details from PHP error handling
         $error = error_get_last();
         if ($error && preg_match('/function\\.pg-connect\\<\\/a\\>\\]\\: (?<message>.*)/', $error['message'], $matches)) {
             $this->databaseError(html_entity_decode($matches['message']));
         } else {
             $this->databaseError("Couldn't connect to PostgreSQL database.");
         }
     } elseif (pg_connection_status($this->dbConn) != PGSQL_CONNECTION_OK) {
         throw new ErrorException($this->getLastError());
     }
     //By virtue of getting here, the connection is active:
     $this->databaseName = empty($parameters['database']) ? PostgreSQLDatabase::MASTER_DATABASE : $parameters['database'];
 }
开发者ID:helpfulrobot,项目名称:silverstripe-postgresql,代码行数:28,代码来源:PostgreSQLConnector.php

示例9: is_connected

 protected function is_connected()
 {
     if (!$this->db) {
         return false;
     }
     if (pg_connection_status($this->db) != PGSQL_CONNECTION_OK) {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:igoan,代码行数:9,代码来源:Igoandb.class.php

示例10: sql_query

function sql_query($qry, &$conn = 0)
{
    global $db;
    // If no database connection is supplied use default
    if (!$conn) {
        $conn =& $db;
    }
    if (!$conn) {
        print "NO DATABASE\n";
        exit;
    }
    // check if connection was opened too long
    if (isset($conn['date']) && time() - $conn['date'] > 3600) {
        debug("connection {$conn['connection']} opened too long, closing", "sql");
        $conn['date'] = null;
        pg_close($conn['connection']);
        unset($conn['connection']);
    }
    // check for database connection
    sql_connect($conn);
    // Rewrite SQL query
    call_hooks("pg_sql_query", $qry, $conn);
    // Do we want debug information?
    if (isset($conn['debug']) && $conn['debug']) {
        debug("CONN {$conn['title']}: " . $qry, "sql");
    }
    // Query
    $res = pg_query($conn['connection'], $qry);
    // There was an error - call hooks to inform about error
    if ($res === false) {
        // if postgresql connection died ...
        if (pg_connection_status($conn['connection']) == PGSQL_CONNECTION_BAD) {
            debug("sql connection died", "sql");
            pg_close($conn['connection']);
            unset($conn['connection']);
            call_hooks("sql_connection_failed", $conn);
            // if connection is back, retry query
            if (isset($conn['connection']) && pg_connection_status($conn['connection']) == PGSQL_CONNECTION_OK) {
                $res = pg_query($conn['connection'], $qry);
                if ($res !== false) {
                    debug("sql retry successful", "sql");
                    return $res;
                }
            } else {
                print "sql connection died\n";
                exit;
            }
        }
        $error = pg_last_error();
        call_hooks("sql_error", $db, $qry, $error);
        // If we want debug information AND we have an error, tell about it
        if (isset($conn['debug']) && $conn['debug']) {
            debug("CONN {$conn['title']}: " . pg_last_error(), "sql");
        }
    }
    return $res;
}
开发者ID:plepe,项目名称:modulekit-lib,代码行数:57,代码来源:sql.php

示例11: db_connect

 function db_connect()
 {
     $uri = "host={$this->mDatabaseHost} port={$this->mDatabasePort} dbname={$this->mDatabaseName} user={$this->mDatabaseUsername} password={$this->mDatabasePassword}";
     $connection = pg_connect($uri);
     if (pg_connection_status($connection) == PGSQL_CONNECTION_OK) {
         return $connection;
     }
     die('数据库访问错误!');
 }
开发者ID:iwater,项目名称:kissphp,代码行数:9,代码来源:PostgreSqlCommand.php

示例12: status

 function status()
 {
     $status = pg_connection_status($this->dbConnection);
     if ($status === PGSQL_CONNECTION_OK) {
         return "Connection status ok";
     } else {
         return "Connection status bad";
     }
 }
开发者ID:atahualpasf,项目名称:hipodromo,代码行数:9,代码来源:respaldodb.php

示例13: ifConnected

 public function ifConnected()
 {
     $stat = pg_connection_status($this->link);
     if ($stat === 0) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:alien-svn,代码行数:9,代码来源:alien_pgsql.php

示例14: db_backend_connection

function db_backend_connection()
{
    $conf = get_config();
    // connect to database
    $db = pg_connect($conf['database']['connect']) or die('Unable to connect to db node server');
    if (pg_connection_status($db) !== PGSQL_CONNECTION_OK) {
        die('db: Bad connection status');
    }
    return $db;
}
开发者ID:T1T4N,项目名称:ncrypt,代码行数:10,代码来源:db-pgsql.inc.php

示例15: connect

 public function connect($connection)
 {
     if (empty($connection)) {
         throw new Exception("Could not connect to any database without reequired connection data");
     } else {
         $this->connection = pg_connect($connection);
         $this->conn_stat = pg_connection_status($this->connection);
         if ($this->conn_stat != PGSQL_CONNECTION_OK) {
             throw new Exception("Could not connect to database... :(");
         }
     }
 }
开发者ID:jankovacs,项目名称:php-legs,代码行数:12,代码来源:PostgreSQL.php


注:本文中的pg_connection_status函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。